Add length metamethod to GPUBuffer

This commit is contained in:
Alessandro Proto 2023-01-21 15:56:32 +01:00
parent 9fad3258c5
commit 3a7914ee6d

View file

@ -27,6 +27,10 @@ public class GPUBuffer
L.PushCFunction(LM_NewIndex);
L.SetTable(-3);
L.PushString("__len");
L.PushCFunction(LM_Length);
L.SetTable(-3);
L.PushString("__gc");
L.PushCFunction(LM_GC);
L.SetTable(-3);
@ -114,4 +118,15 @@ public class GPUBuffer
return 0;
}
private static int LM_Length(IntPtr state)
{
var L = Lua.FromIntPtr(state);
var buffer = L.CheckObject<uint[]>(1, ObjectType, false);
L.PushInteger(buffer.LongLength);
return 1;
}
}