Skip to content

Commit ec06506

Browse files
committed
feat: add DaedalusInstance UserData
1 parent d26fd0c commit ec06506

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed

ZenKit/DaedalusInstance.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.InteropServices;
23
using ZenKit.Daedalus;
34

45
namespace ZenKit
@@ -42,6 +43,21 @@ protected DaedalusInstance(UIntPtr handle)
4243
public DaedalusInstanceType Type => Native.ZkDaedalusInstance_getType(Handle);
4344
public int Index => (int)Native.ZkDaedalusInstance_getIndex(Handle);
4445

46+
public object? UserData
47+
{
48+
get
49+
{
50+
var userPtr = Native.ZkDaedalusInstance_getUserPointer(Handle);
51+
return userPtr == IntPtr.Zero ? null : GCHandle.FromIntPtr(userPtr).Target;
52+
}
53+
set
54+
{
55+
// TODO: This leaks a handle.
56+
var handle = GCHandle.Alloc(value, GCHandleType.Weak);
57+
Native.ZkDaedalusInstance_setUserPointer(Handle, GCHandle.ToIntPtr(handle));
58+
}
59+
}
60+
4561
public static DaedalusInstance? FromNative(UIntPtr handle)
4662
{
4763
if (handle == UIntPtr.Zero) return null;

ZenKit/Native.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,6 +4027,12 @@ public static extern void ZkDaedalusScript_enumerateInstanceSymbols(UIntPtr slf,
40274027

40284028
[DllImport(DllName)]
40294029
public static extern uint ZkDaedalusInstance_getIndex(UIntPtr ptr);
4030+
4031+
[DllImport(DllName)]
4032+
public static extern IntPtr ZkDaedalusInstance_getUserPointer(UIntPtr slf);
4033+
4034+
[DllImport(DllName)]
4035+
public static extern void ZkDaedalusInstance_setUserPointer(UIntPtr slf, IntPtr ptr);
40304036

40314037
[DllImport(DllName)]
40324038
public static extern UIntPtr ZkDaedalusVm_load(UIntPtr buf);
560 Bytes
Binary file not shown.
120 Bytes
Binary file not shown.
152 Bytes
Binary file not shown.
460 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)