mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Has taken too much time now, rip 6 hours
This commit is contained in:
@@ -244,15 +244,18 @@ Manager.sandbox = setmetatable({
|
|||||||
-- creates a new sandbox env
|
-- creates a new sandbox env
|
||||||
local sandbox = tbl()
|
local sandbox = tbl()
|
||||||
local env = type(env) == 'table' 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 _G_mt = getmetatable(_G)
|
||||||
local old_mt = getmetatable(_G) or {}
|
-- creates a new ENV where it will look in the provided env then the sand box and then _G, new indexes saved to sandbox
|
||||||
local tmp_env = setmetatable({},{__index=function(tbl,key) return env[key] or sandbox[key] end})
|
local tmp_env = setmetatable({},{__index=function(tbl,key) return env[key] or sandbox[key] or rawget(_G,key) end,newindex=sandbox})
|
||||||
setmetatable(_G,{__index=tmp_env,__newindex=sandbox})
|
tmp_env._ENV = tmp_env
|
||||||
|
tmp_env._G_mt = _G_mt
|
||||||
-- runs the callback
|
-- runs the callback
|
||||||
|
setmetatable(_G,{__index=tmp_env,newindex=sandbox})
|
||||||
|
--debug.setupvalue(callback,1,tmp_env) -- this should set the value of _ENV
|
||||||
local rtn = {pcall(callback,...)}
|
local rtn = {pcall(callback,...)}
|
||||||
local success = table.remove(rtn,1)
|
local success = table.remove(rtn,1)
|
||||||
|
setmetatable(_G,_G_mt)
|
||||||
-- this is to allow modules to be access with out the need of using Mangaer[name] also keeps global clean
|
-- this is to allow modules to be access with out the need of using Mangaer[name] also keeps global clean
|
||||||
setmetatable(_G,old_mt)
|
|
||||||
if success then return success, rtn, sandbox
|
if success then return success, rtn, sandbox
|
||||||
else return success, rtn[1], sandbox end
|
else return success, rtn[1], sandbox end
|
||||||
else return setmetatable({},{__index=tbl}) end
|
else return setmetatable({},{__index=tbl}) end
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ end
|
|||||||
-- @treturn table the env table with _G keys removed
|
-- @treturn table the env table with _G keys removed
|
||||||
-- @warning does not work from console
|
-- @warning does not work from console
|
||||||
function ExpLib.get_upvalues(level)
|
function ExpLib.get_upvalues(level)
|
||||||
local level = level and level+1 or 2
|
local func = level and ExpLib.is_type(level,'function') and level or nil
|
||||||
local func = debug.getinfo(level).func
|
local level = level and ExpLib.is_type(level,'number') and level+1 or 2
|
||||||
|
func = func or debug.getinfo(level).func
|
||||||
local upvalues = setmetatable({},{__index=_G})
|
local upvalues = setmetatable({},{__index=_G})
|
||||||
local i = 1
|
local i = 1
|
||||||
while true do
|
while true do
|
||||||
|
|||||||
Reference in New Issue
Block a user