mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
update cbind
This commit is contained in:
parent
8ff60df158
commit
862b3aa436
@ -1,5 +1,5 @@
|
||||
from .writer import Writer
|
||||
from .types import C_INT_TYPES, C_FLOAT_TYPES, C_BOOL_TYPES, C_STRING_TYPES, LINALG_TYPES
|
||||
from .types import C_INT_TYPES, C_FLOAT_TYPES, C_BOOL_TYPES, C_STRING_TYPES, VMATH_TYPES
|
||||
|
||||
class Converter:
|
||||
def __init__(self, T: str):
|
||||
@ -110,7 +110,7 @@ class VoidConverter(Converter):
|
||||
def py_T(self) -> str:
|
||||
return 'None'
|
||||
|
||||
class BuiltinVectorConverter(Converter):
|
||||
class BuiltinVMathConverter(Converter):
|
||||
def __init__(self, T: str, py_builtin_T: str):
|
||||
super().__init__(T)
|
||||
self.py_builtin_T = py_builtin_T
|
||||
@ -143,15 +143,21 @@ for t in C_BOOL_TYPES:
|
||||
_CONVERTERS[t] = BoolConverter(t)
|
||||
for t in C_STRING_TYPES:
|
||||
_CONVERTERS[t] = StringConverter(t)
|
||||
for t in LINALG_TYPES:
|
||||
_CONVERTERS[t] = BuiltinVectorConverter(f'c11_{t}', t)
|
||||
for t in VMATH_TYPES:
|
||||
_CONVERTERS[t] = BuiltinVMathConverter(f'c11_{t}', t)
|
||||
|
||||
_CONVERTERS['void'] = VoidConverter('void')
|
||||
_CONVERTERS['c11_array2d'] = StructConverter('c11_array2d', 'tp_array2d')
|
||||
|
||||
def is_vmath_type(T: str) -> bool:
|
||||
cvt = _CONVERTERS.get(T)
|
||||
if cvt is None:
|
||||
return False
|
||||
return isinstance(cvt, BuiltinVMathConverter)
|
||||
|
||||
def set_vmath_converter(T: str, py_T: str):
|
||||
assert py_T in LINALG_TYPES
|
||||
_CONVERTERS[T] = BuiltinVectorConverter(T, py_T)
|
||||
assert py_T in VMATH_TYPES
|
||||
_CONVERTERS[T] = BuiltinVMathConverter(T, py_T)
|
||||
|
||||
def set_enum_converters(enums: list[str]):
|
||||
for T in enums:
|
||||
@ -167,3 +173,4 @@ def get_converter(T: str) -> Converter:
|
||||
cvt = _CONVERTERS.get(T)
|
||||
if cvt is None:
|
||||
return StructConverter(T, None)
|
||||
return cvt
|
||||
|
@ -3,6 +3,7 @@ from .writer import Writer
|
||||
from .enum import gen_enum
|
||||
from .struct import gen_struct
|
||||
from .function import gen_function
|
||||
from .converters import is_vmath_type
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
@ -18,10 +19,7 @@ class Library:
|
||||
self.functions = [] # type: list[Function]
|
||||
self.callbacks = set() # type: set[str]
|
||||
|
||||
def set_includes(self, includes: list[str]):
|
||||
self.user_includes.extend(includes)
|
||||
|
||||
def build(self, *, glue_dir='.', stub_dir='.', includes: list[str] = None):
|
||||
def build(self, *, glue_dir='.', stub_dir='.', includes: list[str] | None = None):
|
||||
self.remove_unsupported()
|
||||
|
||||
w, pyi_w = Writer(), Writer()
|
||||
@ -113,6 +111,10 @@ class Library:
|
||||
def from_raylib(data: dict):
|
||||
self = Library('raylib')
|
||||
for struct in data['structs']:
|
||||
name = struct['name']
|
||||
if is_vmath_type(name):
|
||||
print(f'[INFO] {name} is a vmath type, skipping')
|
||||
continue
|
||||
self.structs.append(Struct(
|
||||
name=struct['name'],
|
||||
desc=struct['description'],
|
||||
@ -162,12 +164,14 @@ class Library:
|
||||
if type.is_opaque():
|
||||
continue
|
||||
else:
|
||||
fields = type.fields
|
||||
assert fields is not None
|
||||
self.structs.append(Struct(
|
||||
name=type.name,
|
||||
fields=[StructField(
|
||||
type=field_type,
|
||||
name=field_name
|
||||
) for field_name, field_type in type.fields.items()]
|
||||
) for field_name, field_type in fields.items()]
|
||||
))
|
||||
elif isinstance(type, schema.Enum):
|
||||
self.enums.append(Enum(
|
||||
|
@ -24,7 +24,7 @@ C_STRING_TYPES = [
|
||||
'const char *',
|
||||
]
|
||||
|
||||
LINALG_TYPES = [
|
||||
VMATH_TYPES = [
|
||||
'vec2', 'vec3', 'vec2i', 'vec3i',
|
||||
'mat3x3'
|
||||
'mat3x3', 'color32'
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user