From 3a7914ee6d4dd621439ac8643fb0be949a8a728d Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Sat, 21 Jan 2023 15:56:32 +0100 Subject: [PATCH] Add length metamethod to GPUBuffer --- Capy64/LuaRuntime/Objects/GPUBuffer.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Capy64/LuaRuntime/Objects/GPUBuffer.cs b/Capy64/LuaRuntime/Objects/GPUBuffer.cs index 9878b8c..c1bd6cf 100644 --- a/Capy64/LuaRuntime/Objects/GPUBuffer.cs +++ b/Capy64/LuaRuntime/Objects/GPUBuffer.cs @@ -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(1, ObjectType, false); + + L.PushInteger(buffer.LongLength); + + return 1; + } }