mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
ac334e83a1
commit
da7d30048b
@ -155,6 +155,10 @@ void _bind(VM* vm, PyObject* obj, const char* sig, Ret(T::*func)(Params...)){
|
||||
vm->bind__hash__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){ \
|
||||
wT& self = _CAST(wT&, obj); \
|
||||
return reinterpret_cast<i64>(self._()); \
|
||||
}); \
|
||||
vm->bind_property(type, "_value: int", [](VM* vm, ArgsView args){ \
|
||||
wT& self = _CAST(wT&, args[0]); \
|
||||
return VAR(reinterpret_cast<i64>(self._())); \
|
||||
});
|
||||
|
||||
} // namespace pkpy
|
@ -16,6 +16,9 @@ class void_p:
|
||||
|
||||
def hex(self) -> str: ...
|
||||
|
||||
@property
|
||||
def _value(self) -> int: ...
|
||||
|
||||
def read_char(self) -> int: ...
|
||||
def read_uchar(self) -> int: ...
|
||||
def read_short(self) -> int: ...
|
||||
@ -148,3 +151,6 @@ class _PointerLike(Generic[T]):
|
||||
def __eq__(self, other) -> bool: ...
|
||||
def __ne__(self, other) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
@property
|
||||
def _value(self) -> int: ...
|
||||
|
@ -1,5 +1,5 @@
|
||||
from typing import overload
|
||||
from c import _StructLike
|
||||
from c import _StructLike, float_p
|
||||
|
||||
class vec2(_StructLike['vec2']):
|
||||
x: float
|
||||
@ -107,3 +107,8 @@ class mat3x3(_StructLike['mat3x3']):
|
||||
|
||||
def transform_point(self, p: vec2) -> vec2: ...
|
||||
def transform_vector(self, v: vec2) -> vec2: ...
|
||||
|
||||
vec2_p = float_p
|
||||
vec3_p = float_p
|
||||
vec4_p = float_p
|
||||
mat3x3_p = float_p
|
||||
|
@ -22,6 +22,11 @@ namespace pkpy{
|
||||
return VAR(ss.str());
|
||||
});
|
||||
|
||||
vm->bind_property(type, "_value: int", [](VM* vm, ArgsView args){
|
||||
VoidP& self = _CAST(VoidP&, args[0]);
|
||||
return VAR(reinterpret_cast<i64>(self.ptr));
|
||||
});
|
||||
|
||||
#define BIND_CMP(name, op) \
|
||||
vm->bind##name(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* lhs, PyObject* rhs){ \
|
||||
if(!is_non_tagged_type(rhs, VoidP::_type(vm))) return vm->NotImplemented; \
|
||||
|
@ -46,7 +46,10 @@ my_struct1 = c.struct(16)
|
||||
c_void_1.write_struct(my_struct1)
|
||||
assert c_void_1.read_struct(16) == my_struct1
|
||||
|
||||
from c import array, int_
|
||||
from c import array, int_, NULL
|
||||
|
||||
assert NULL._value == 0
|
||||
|
||||
a = array(10, item_size=4)
|
||||
assert a.item_count == 10
|
||||
assert a.item_size == 4
|
||||
|
Loading…
x
Reference in New Issue
Block a user