diff --git a/package/ctypes/ctypes.c b/package/ctypes/ctypes.c new file mode 100644 index 000000000..f455c998e --- /dev/null +++ b/package/ctypes/ctypes.c @@ -0,0 +1,16 @@ +#include "ctypes_Test.h" +#include "ctypes_cUint.h" +#include "ctypes_cWcharP.h" +void ctypes_cUint___init__(PikaObj* self, int value) { + obj_setInt(self, "value", value); +} + +void ctypes_cWcharP___init__(PikaObj* self, char* value) { + obj_setStr(self, "value", value); +} + +int ctypes_Test_add(PikaObj* self, void* c_uint1, void* c_uint2) { + PikaObj* c_uint1_obj = c_uint1; + PikaObj* c_uint2_obj = c_uint2; + return obj_getInt(c_uint1_obj, "value") + obj_getInt(c_uint2_obj, "value"); +} diff --git a/package/ctypes/ctypes.py b/package/ctypes/ctypes.py new file mode 100644 index 000000000..4eafe3dc2 --- /dev/null +++ b/package/ctypes/ctypes.py @@ -0,0 +1,13 @@ +from PikaObj import * + +class cUint(TinyObj): + def __init__(self, value:int): + pass + +class cWcharP(TinyObj): + def __init__(self, value:str): + pass + +class Test(TinyObj): + def add(self, c_uint1:pointer, c_uint2:pointer)->int: + pass diff --git a/port/linux/.vscode/settings.json b/port/linux/.vscode/settings.json index aa733167a..246722e76 100644 --- a/port/linux/.vscode/settings.json +++ b/port/linux/.vscode/settings.json @@ -50,7 +50,9 @@ "PikaParser.H": "cpp", "pikastddata_list.h": "c", "pikastddevice_spi.h": "c", - "pikastddevice_can.h": "c" + "pikastddevice_can.h": "c", + "ctypes.h": "c", + "ctypes_test.h": "c" }, "python.formatting.provider": "autopep8" } \ No newline at end of file diff --git a/port/linux/package/pikascript/ctypes.py b/port/linux/package/pikascript/ctypes.py new file mode 100644 index 000000000..4eafe3dc2 --- /dev/null +++ b/port/linux/package/pikascript/ctypes.py @@ -0,0 +1,13 @@ +from PikaObj import * + +class cUint(TinyObj): + def __init__(self, value:int): + pass + +class cWcharP(TinyObj): + def __init__(self, value:str): + pass + +class Test(TinyObj): + def add(self, c_uint1:pointer, c_uint2:pointer)->int: + pass diff --git a/port/linux/package/pikascript/main.py b/port/linux/package/pikascript/main.py index 315f7c935..a915c2c84 100644 --- a/port/linux/package/pikascript/main.py +++ b/port/linux/package/pikascript/main.py @@ -4,7 +4,7 @@ import GTestTask import PikaMath import PikaStdDevice import PikaDebug +import ctypes import PikaStdData -from package.pikascript.PikaObj import printNoEnd mem = PikaStdLib.MemChecker() diff --git a/port/linux/package/pikascript/pikascript-lib/ctypes/ctypes.c b/port/linux/package/pikascript/pikascript-lib/ctypes/ctypes.c new file mode 100644 index 000000000..f455c998e --- /dev/null +++ b/port/linux/package/pikascript/pikascript-lib/ctypes/ctypes.c @@ -0,0 +1,16 @@ +#include "ctypes_Test.h" +#include "ctypes_cUint.h" +#include "ctypes_cWcharP.h" +void ctypes_cUint___init__(PikaObj* self, int value) { + obj_setInt(self, "value", value); +} + +void ctypes_cWcharP___init__(PikaObj* self, char* value) { + obj_setStr(self, "value", value); +} + +int ctypes_Test_add(PikaObj* self, void* c_uint1, void* c_uint2) { + PikaObj* c_uint1_obj = c_uint1; + PikaObj* c_uint2_obj = c_uint2; + return obj_getInt(c_uint1_obj, "value") + obj_getInt(c_uint2_obj, "value"); +}