From e3c6d3fb4f73145b19b4d401ea15e8286b9126f0 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 25 Oct 2018 16:43:17 +0100 Subject: [PATCH] Fixed Manager.Sandbox --- FactorioSoftmodManager.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index e4a67bd6..c5c72af6 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -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,...)}