mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Fixed metatables being different
This commit is contained in:
@@ -263,6 +263,10 @@ end
|
|||||||
-- @field data any data that the thread will beable to access
|
-- @field data any data that the thread will beable to access
|
||||||
Server._thread = {}
|
Server._thread = {}
|
||||||
|
|
||||||
|
local _env_metatable = {
|
||||||
|
__index=function(tbl,key) if rawget(tbl,'_modules') and tbl._modules[key] then return require(tbl._modules[key]) end end
|
||||||
|
}
|
||||||
|
|
||||||
--- Returns a new thread object
|
--- Returns a new thread object
|
||||||
-- @usage new_thread = thread:create()
|
-- @usage new_thread = thread:create()
|
||||||
-- @tparam[opt={}] table obj all values are opt {timeout=int,name=str,data=any}
|
-- @tparam[opt={}] table obj all values are opt {timeout=int,name=str,data=any}
|
||||||
@@ -274,15 +278,11 @@ function Server._thread:create(obj)
|
|||||||
-- creates a varible containg all upvalus for the thread (stops desyncs)
|
-- 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
|
obj._env._env = true
|
||||||
|
obj._env._ENV = nil -- provents infinte recusion
|
||||||
-- removes any modules from the _env to save space in global (less time to serizle)
|
-- 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 is_type(value,'table') and 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 is_type(value,'table') and value._module_name and loaded_modules[value._module_name] == value then obj._env._modules[name] = value._module_name obj._env[name] = nil end end
|
||||||
-- metatable allows these modules to be called by there orignial
|
setmetatable(obj._env,_env_metatable)
|
||||||
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
|
||||||
@@ -492,9 +492,7 @@ 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
|
for uuid,thread in pairs(Server.threads) do
|
||||||
setmetatable(thread,{__index=Server._thread})
|
setmetatable(thread,{__index=Server._thread})
|
||||||
setmetatable(thread._env,{
|
setmetatable(thread._env,_env_metatable)
|
||||||
__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)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user