Skip to content

Commit

Permalink
[#10] fix(DaedalusVm): allow Push to push null instances
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Sep 15, 2024
1 parent f3e323f commit f1e6670
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ZenKit/DaedalusVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ private void Push<T>(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());
}
Expand All @@ -674,7 +677,14 @@ private T Pop<T>()
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));
Expand Down

0 comments on commit f1e6670

Please sign in to comment.