mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Fixed _Env and _Modules
This commit is contained in:
@@ -271,11 +271,18 @@ function Server._thread:create(obj)
|
|||||||
local obj = obj or {}
|
local obj = obj or {}
|
||||||
setmetatable(obj,{__index=Server._thread})
|
setmetatable(obj,{__index=Server._thread})
|
||||||
obj.uuid = tostring(Server.uuid)
|
obj.uuid = tostring(Server.uuid)
|
||||||
|
-- creates a varible containg all upvalus for the thread (stops desyncs)
|
||||||
obj._env = get_upvalues(2)
|
obj._env = get_upvalues(2)
|
||||||
|
obj._env._env = true
|
||||||
|
-- removes any modules from the _env to save space in global (less time to serizle)
|
||||||
obj._env._modules = {}
|
obj._env._modules = {}
|
||||||
for name,value in pairs(obj._env) do if value._module_name and loaded_modules[value._module_name] == value then obj._env._modules[name] = value._module_name obj._env[name] = nil end end
|
for name,value in pairs(obj._env) do if value._module_name and loaded_modules[value._module_name] == value then obj._env._modules[name] = value._module_name obj._env[name] = nil end end
|
||||||
obj._env._env = true
|
-- metatable allows these modules to be called by there orignial
|
||||||
obj._env._ENV = nil -- provents infinte recusion
|
setmetatable(obj._env,{
|
||||||
|
__index=function(tbl,key) verbose(serpent.line(tbl)) verbose(key) if rawget(tbl,'_modules') and tbl._modules[key] then return require(tbl._modules[key]) end end
|
||||||
|
})
|
||||||
|
-- provents infinte recusion
|
||||||
|
obj._env._ENV = nil
|
||||||
local name = obj.name or 'Anon'
|
local name = obj.name or 'Anon'
|
||||||
verbose('Created new thread: '..name..' ('..obj.uuid..')')
|
verbose('Created new thread: '..name..' ('..obj.uuid..')')
|
||||||
return obj
|
return obj
|
||||||
@@ -483,7 +490,12 @@ end)
|
|||||||
|
|
||||||
script.on_event(-2,function(event)
|
script.on_event(-2,function(event)
|
||||||
-- sets up metatable again so that threads contiune to work
|
-- sets up metatable again so that threads contiune to work
|
||||||
for uuid,thread in pairs(Server.threads) do setmetatable(thread,{__index=Server._thread}) setmetatable(thread._env,{__index=function(tbl,key) if rawget(tbl,'_modules') and tbl._modules[key] then return require(tbl._modules[key]) end end}) end
|
for uuid,thread in pairs(Server.threads) do
|
||||||
|
setmetatable(thread,{__index=Server._thread})
|
||||||
|
setmetatable(thread._env,{
|
||||||
|
__index=function(tbl,key) verbose(serpent.line(tbl)) verbose(key) if rawget(tbl,'_modules') and tbl._modules[key] then return require(tbl._modules[key]) end end
|
||||||
|
})
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function Server:on_init()
|
function Server:on_init()
|
||||||
|
|||||||
Reference in New Issue
Block a user