blueloveTH %!s(int64=2) %!d(string=hai) anos
pai
achega
da7d30048b
Modificáronse 5 ficheiros con 25 adicións e 2 borrados
  1. 4 0
      include/pocketpy/bindings.h
  2. 6 0
      include/typings/c.pyi
  3. 6 1
      include/typings/linalg.pyi
  4. 5 0
      src/cffi.cpp
  5. 4 1
      tests/99_cffi_2.py

+ 4 - 0
include/pocketpy/bindings.h

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

+ 6 - 0
include/typings/c.pyi

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

+ 6 - 1
include/typings/linalg.pyi

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

+ 5 - 0
src/cffi.cpp

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

+ 4 - 1
tests/99_cffi_2.py

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