mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
Fix to loading modules inside threads
This commit is contained in:
@@ -271,8 +271,11 @@ function Server._thread:create(obj)
|
||||
local obj = obj or {}
|
||||
setmetatable(obj,{__index=Server._thread})
|
||||
obj.uuid = tostring(Server.uuid)
|
||||
obj._env = get_env()
|
||||
obj._env.obj = nil -- provents infinte recusion
|
||||
obj._env = get_upvalues(2)
|
||||
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
|
||||
obj._env._env = true
|
||||
obj._env._ENV = nil -- provents infinte recusion
|
||||
local name = obj.name or 'Anon'
|
||||
verbose('Created new thread: '..name..' ('..obj.uuid..')')
|
||||
return obj
|
||||
@@ -480,7 +483,7 @@ end)
|
||||
|
||||
script.on_event(-2,function(event)
|
||||
-- sets up metatable again so that threads contiune to work
|
||||
for uuid,thread in pairs(Server.threads) do setmetatable(thread,{__index=Server._thread}) end
|
||||
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
|
||||
end)
|
||||
|
||||
function Server:on_init()
|
||||
|
||||
Reference in New Issue
Block a user