LuaJIT/src/clear_globals.lua
2024-06-26 16:39:25 +02:00

23 lines
556 B
Lua

local clear = {}
function table_contains(tbl, x)
found = false
for _, v in pairs(tbl) do
if v == x then
found = true
end
end
return found
end
WHITELIST = {"_G", "WHITELIST", "clearAllGlobals", "print", "k",
"v", "pairs", "table_contains", "string", "table",
"tonumber", "tostring", "type", "f"}
function clear.clearAllGlobals()
for k, v in pairs(_G) do
if not table_contains(WHITELIST, tostring(k)) then _G[k] = nil end;
end
end
return clear