So I just found that page on the wiki about sandboxing but there's something i don't understand in the code:
function runInSandbox(f)
--get the old function environment
local oldenv = getfenv(f)
--create a new one
local newenv = setmetatable({}, {
__index = function(t, k)
if k:lower() == 'game' or k:lower() == 'workspace' or k == 'Instance' then
--that prevents any instances being accessed
return nil
else
--but otherwise defaults to the old one
return oldenv[k]
end
end
})
--call the function in its new environment
setfenv(f, newenv)
f()
end
"if k:lower() == 'game' or k:lower() == 'workspace' or k == 'Instance'"
"k" is the key right?
How can the key == 'game' or 'workspace'?
Isn't it meant to be t[k] == 'game' or 'workspace' ? |