Fixed Manager.Sandbox

This commit is contained in:
Cooldude2606
2018-10-25 16:43:17 +01:00
parent 565de3f629
commit e3c6d3fb4f

View File

@@ -243,10 +243,11 @@ Manager.sandbox = setmetatable({
if type(callback) == 'function' then
-- creates a new sandbox env
local sandbox = tbl()
local env = type(env) == 'table' and env or type(env) ~= 'nil' and {env} or {}
local env = type(env) == 'table' and env or {}
-- new indexs are saved into sandbox and if _G does not have the index then look in sandbox
local old_mt = getmetatable(_G) or {}
setmetatable(env,{__index=sandbox})
local env_mt = getmetatable(env) or {}
setmetatable(env,{__index=function(tbl,key) return env_mt.__index and env_mt.__index(tbl,key) or sandbox[key] end})
setmetatable(_G,{__index=env,__newindex=sandbox})
-- runs the callback
local rtn = {pcall(callback,...)}