Skip to content

Commit 37a16c1

Browse files
committed
feat: nicer print for instances
1 parent 697661f commit 37a16c1

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/zenkit/daedalus/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ class DaedalusInstance:
4242

4343
def __init__(self, **kwargs: Any) -> None:
4444
self._handle = None
45+
self._sym = None
4546

4647
if "_handle" in kwargs:
4748
self._handle = kwargs.pop("_handle")
4849

50+
if "_sym" in kwargs:
51+
self._sym = kwargs.pop("_sym")
52+
4953
@staticmethod
50-
def from_native(handle: c_void_p | None) -> "DaedalusInstance | None":
54+
def from_native(handle: c_void_p | None, sym: "DaedalusSymbol") -> "DaedalusInstance | None":
5155
from zenkit.daedalus import _INSTANCES
5256

5357
print(handle, handle.value if handle is not None else None)
@@ -57,7 +61,7 @@ def from_native(handle: c_void_p | None) -> "DaedalusInstance | None":
5761
DLL.ZkDaedalusInstance_getType.restype = c_int
5862
typ = DaedalusInstanceType(DLL.ZkDaedalusInstance_getType(handle))
5963

60-
return _INSTANCES.get(typ, DaedalusInstance)(_handle=handle)
64+
return _INSTANCES.get(typ, DaedalusInstance)(_handle=handle, _sym=sym)
6165

6266
@property
6367
def handle(self) -> c_void_p:
@@ -72,3 +76,6 @@ def type(self) -> DaedalusInstanceType:
7276
def index(self) -> int:
7377
DLL.ZkDaedalusInstance_getIndex.restype = c_uint32
7478
return DLL.ZkDaedalusInstance_getIndex(self._handle)
79+
80+
def __str__(self) -> str:
81+
return f"{self.__class__.__name__}({self._sym.name})"

src/zenkit/daedalus_vm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def init_instance(self, sym: DaedalusSymbol | str, typ: DaedalusInstanceType) ->
148148
sym = self.get_symbol_by_name(sym)
149149

150150
handle = DLL.ZkDaedalusVm_initInstance(self._handle, sym.handle, typ.value).value
151-
return DaedalusInstance.from_native(handle)
151+
return DaedalusInstance.from_native(handle, sym)
152152

153153
def init_instance_direct(self, sym: DaedalusInstance) -> None:
154154
DLL.ZkDaedalusVm_initInstanceDirect(self._handle, sym.handle)

0 commit comments

Comments
 (0)