Added GC functions to handles

This commit is contained in:
Alessandro Proto 2023-01-17 22:15:50 +01:00
parent 79c232a4ac
commit 916662bebd
4 changed files with 40 additions and 0 deletions

View file

@ -40,6 +40,16 @@ public class BinaryReadHandle : IHandle
if (newTable) if (newTable)
L.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) foreach (var pair in functions)
{ {
L.PushString(pair.Key); L.PushString(pair.Key);

View file

@ -40,6 +40,16 @@ public class BinaryWriteHandle : IHandle
if (newTable) if (newTable)
L.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) foreach (var pair in functions)
{ {
L.PushString(pair.Key); L.PushString(pair.Key);

View file

@ -27,6 +27,16 @@ public class ReadHandle : IHandle
if (newTable) if (newTable)
L.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) foreach (var pair in functions)
{ {
L.PushString(pair.Key); L.PushString(pair.Key);

View file

@ -32,6 +32,16 @@ public class WriteHandle : IHandle
if (newTable) if (newTable)
L.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) foreach (var pair in functions)
{ {
L.PushString(pair.Key); L.PushString(pair.Key);