From 916662bebda19c3064497c1da7de1a29771957e6 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Tue, 17 Jan 2023 22:15:50 +0100 Subject: [PATCH] Added GC functions to handles --- Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs | 10 ++++++++++ Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs | 10 ++++++++++ Capy64/LuaRuntime/Handlers/ReadHandle.cs | 10 ++++++++++ Capy64/LuaRuntime/Handlers/WriteHandle.cs | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs b/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs index 309be16..4a8e248 100644 --- a/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs +++ b/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs @@ -40,6 +40,16 @@ public class BinaryReadHandle : IHandle if (newTable) L.NewTable(); + // metatable + L.NewTable(); + L.PushString("__close"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.PushString("__gc"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.SetMetaTable(-2); + foreach (var pair in functions) { L.PushString(pair.Key); diff --git a/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs b/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs index af1e363..5055c98 100644 --- a/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs +++ b/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs @@ -40,6 +40,16 @@ public class BinaryWriteHandle : IHandle if (newTable) L.NewTable(); + // metatable + L.NewTable(); + L.PushString("__close"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.PushString("__gc"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.SetMetaTable(-2); + foreach (var pair in functions) { L.PushString(pair.Key); diff --git a/Capy64/LuaRuntime/Handlers/ReadHandle.cs b/Capy64/LuaRuntime/Handlers/ReadHandle.cs index 2a6dd52..5152869 100644 --- a/Capy64/LuaRuntime/Handlers/ReadHandle.cs +++ b/Capy64/LuaRuntime/Handlers/ReadHandle.cs @@ -27,6 +27,16 @@ public class ReadHandle : IHandle if (newTable) L.NewTable(); + // metatable + L.NewTable(); + L.PushString("__close"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.PushString("__gc"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.SetMetaTable(-2); + foreach (var pair in functions) { L.PushString(pair.Key); diff --git a/Capy64/LuaRuntime/Handlers/WriteHandle.cs b/Capy64/LuaRuntime/Handlers/WriteHandle.cs index eb82202..4771036 100644 --- a/Capy64/LuaRuntime/Handlers/WriteHandle.cs +++ b/Capy64/LuaRuntime/Handlers/WriteHandle.cs @@ -32,6 +32,16 @@ public class WriteHandle : IHandle if (newTable) L.NewTable(); + // metatable + L.NewTable(); + L.PushString("__close"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.PushString("__gc"); + L.PushCFunction(L_Close); + L.SetTable(-3); + L.SetMetaTable(-2); + foreach (var pair in functions) { L.PushString(pair.Key);