Skip to content

Commit

Permalink
Push nil if we don't have anything also delete everything properly
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Nov 18, 2023
1 parent 2d101db commit 5de1226
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions source/lua_threaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ void PushValue(ILuaBase* LUA, ILuaValue* value)
}
break;
default:
LUA->PushNil();
break;
}
}
Expand All @@ -440,6 +441,18 @@ LUA_FUNCTION(LuaThread_GetTable)
return 1;
}

void SafeDelete(ILuaValue* value)
{
if (value->type == Type::Table)
{
for (auto& [key, val] : value->tbl)
{
SafeDelete(val);
}
}

delete value;
}

ILuaValue* GetOrCreate(std::string key)
{
Expand All @@ -448,8 +461,17 @@ ILuaValue* GetOrCreate(std::string key)
{
ILuaValue* val = it->second;

if (val)
if (val) {
if (val->type == Type::Table)
{
for (auto& [key, val] : val->tbl)
{
SafeDelete(val);
}
}

return val;
}
}

return new ILuaValue;
Expand Down Expand Up @@ -521,7 +543,7 @@ LUA_FUNCTION(LuaThread_SetValue)
if (val)
{
shared_table.erase(key);
delete val;
SafeDelete(val);
}
shared_table_mutex.Unlock();

Expand Down

0 comments on commit 5de1226

Please sign in to comment.