From f1e667047120c0be60bd95dd0976dd4a1921c271 Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Sun, 15 Sep 2024 10:32:38 +0200 Subject: [PATCH] [#10] fix(DaedalusVm): allow `Push` to push `null` instances --- ZenKit/DaedalusVm.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ZenKit/DaedalusVm.cs b/ZenKit/DaedalusVm.cs index ef0bb8d..b12522e 100644 --- a/ZenKit/DaedalusVm.cs +++ b/ZenKit/DaedalusVm.cs @@ -661,6 +661,9 @@ private void Push(T value) case DaedalusInstance v: Native.ZkDaedalusVm_pushInstance(Handle, v.Handle); break; + case null: + Native.ZkDaedalusVm_pushInstance(Handle, UIntPtr.Zero); + break; default: throw new InvalidOperationException("Unsupported type: " + value?.GetType()); } @@ -674,7 +677,14 @@ private T Pop() return (T)(object)Native.ZkDaedalusVm_popInt(Handle); if (typeof(T) == typeof(float)) return (T)(object)Native.ZkDaedalusVm_popFloat(Handle); if (typeof(T) == typeof(DaedalusInstance) || typeof(T).IsSubclassOf(typeof(DaedalusInstance))) - return (T)(object)DaedalusInstance.FromNative(Native.ZkDaedalusVm_popInstance(Handle)); + { + var ptr = Native.ZkDaedalusVm_popInstance(Handle); + if (ptr == UIntPtr.Zero) + { + return (T)(object) null; + } + return (T)(object)DaedalusInstance.FromNative(ptr); + } if (typeof(T) == typeof(void)) return (T)new object(); throw new InvalidOperationException("Unsupported type: " + typeof(T));