Skip to content

Commit 820f058

Browse files
committed
feat: better __str__ for instances
fix: remove print from instance creation
1 parent 697661f commit 820f058

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/zenkit/daedalus/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ 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

53-
print(handle, handle.value if handle is not None else None)
5457
if handle is None or handle.value is None or handle.value == 0 or (isinstance(handle.value, c_void_p) and handle.value.value == None):
5558
return None
5659

5760
DLL.ZkDaedalusInstance_getType.restype = c_int
5861
typ = DaedalusInstanceType(DLL.ZkDaedalusInstance_getType(handle))
5962

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

6265
@property
6366
def handle(self) -> c_void_p:
@@ -72,3 +75,6 @@ def type(self) -> DaedalusInstanceType:
7275
def index(self) -> int:
7376
DLL.ZkDaedalusInstance_getIndex.restype = c_uint32
7477
return DLL.ZkDaedalusInstance_getIndex(self._handle)
78+
79+
def __str__(self) -> str:
80+
return f"{self.__class__.__name__}({self._sym.name})"

src/zenkit/daedalus_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def set_float(self, val: float, i: int = 0, ctx: DaedalusInstance | None = None)
141141

142142
def get_instance(self) -> DaedalusInstance:
143143
value = DLL.ZkDaedalusSymbol_getInstance(self._handle)
144-
return DaedalusInstance.from_native(value)
144+
return DaedalusInstance.from_native(value, self)
145145

146146
def get_parent_as_symbol(self, find_root: bool = False) -> "DaedalusSymbol | None":
147147
if self.parent < 0:

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)