Skip to content

Commit

Permalink
Fixed no deallocation upon garbage collection
Browse files Browse the repository at this point in the history
Had been under the assumption Lua would handle the disposal of basic userdata when no `__gc` metamethod was otherwise specified. This assumption was incorrect.
  • Loading branch information
piqey committed Dec 22, 2023
1 parent 258b321 commit 59310b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Types/PVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ namespace VisInfo::Types
return 1;
}

LUA_FUNCTION_STATIC(gc)
{
LUA->CheckType(1, PVSData::meta);
delete LUA->GetUserType<PVSData>(1, PVSData::meta);

return 0;
}

LUA_FUNCTION_STATIC(unm)
{
LUA->CheckType(1, PVSData::meta);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Types/PVS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 59310b3

Please sign in to comment.