This commit is contained in:
blueloveTH 2023-09-29 14:57:54 +08:00
parent ac334e83a1
commit da7d30048b
5 changed files with 25 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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