add ctypes package

This commit is contained in:
lyon1998 2022-04-16 00:02:41 +08:00
parent 2d5a5c3f3e
commit 32cc9d20bd
6 changed files with 62 additions and 2 deletions

16
package/ctypes/ctypes.c Normal file
View File

@ -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");
}

13
package/ctypes/ctypes.py Normal file
View File

@ -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

View File

@ -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"
}

View File

@ -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

View File

@ -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()

View File

@ -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");
}