From 59310b350c0550ba94d9d8c7ff11d54b9601cfcc Mon Sep 17 00:00:00 2001 From: John Connor Date: Fri, 22 Dec 2023 14:48:52 -0500 Subject: [PATCH] Fixed no deallocation upon garbage collection Had been under the assumption Lua would handle the disposal of basic userdata when no `__gc` metamethod was otherwise specified. This assumption was incorrect. --- src/Types/PVS.cpp | 11 +++++++++++ src/Types/PVS.hpp | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Types/PVS.cpp b/src/Types/PVS.cpp index d1cc035..7c39619 100644 --- a/src/Types/PVS.cpp +++ b/src/Types/PVS.cpp @@ -197,6 +197,14 @@ namespace VisInfo::Types return 1; } + LUA_FUNCTION_STATIC(gc) + { + LUA->CheckType(1, PVSData::meta); + delete LUA->GetUserType(1, PVSData::meta); + + return 0; + } + LUA_FUNCTION_STATIC(unm) { LUA->CheckType(1, PVSData::meta); @@ -361,6 +369,9 @@ namespace VisInfo::Types L->PushCFunction(tostring); L->SetField(-2, "__tostring"); + L->PushCFunction(gc); + L->SetField(-2, "__gc"); + // Arithmetic Metamethods L->PushCFunction(unm); diff --git a/src/Types/PVS.hpp b/src/Types/PVS.hpp index 71b5eab..2498e13 100644 --- a/src/Types/PVS.hpp +++ b/src/Types/PVS.hpp @@ -10,8 +10,8 @@ extern IVDebugOverlay* debug_overlay; const QAngle qZero; // I don't know why vec3_angle is unresolved - extern inline void LuaPrint(GarrysMod::Lua::ILuaBase* L, char* msg); - extern inline void LuaPrint(GarrysMod::Lua::ILuaBase* L, char* msg, int num); +extern inline void LuaPrint(GarrysMod::Lua::ILuaBase* L, char* msg); +extern inline void LuaPrint(GarrysMod::Lua::ILuaBase* L, char* msg, int num); namespace VisInfo::Types {