Refactor global environment setup by removing redundant assignments to _ENV
This commit is contained in:
1 parent
42fe204615
commit
68aa645494
2 files changed
+13
-3
No files matched your search
@@ -22,7 +22,7 @@ function Bridge.RegisterModule(moduleName, moduleTable)
|
||||
end
|
||||
Bridge[moduleName] = wrappedModule
|
||||
_ENV[moduleName] = wrappedModule -- Add to the ENV table the modules so is more easy and safe to call from inside
|
||||
_ENV.Bridge = Bridge -- Add the bridge too to the _ENV
|
||||
|
||||
|
||||
exports(moduleName, function()
|
||||
return wrappedModule
|
||||
@@ -31,6 +31,7 @@ function Bridge.RegisterModule(moduleName, moduleTable)
|
||||
--trigger update object event
|
||||
TriggerEvent("Bridge:Refresh", moduleName, wrappedModule)
|
||||
end
|
||||
|
||||
CreateThread(function() -- lets try to load the lib first to use it on the rest of the modules
|
||||
for k, v in pairs(cLib) do
|
||||
if v then
|
||||
@@ -38,6 +39,17 @@ CreateThread(function() -- lets try to load the lib first to use it on the rest
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- @module GlobalEnvironment
|
||||
--- @field cLib table # Core library utilities, available globally after initialization.
|
||||
--- @field Require fun(module: string): any # Function to require/load modules by name.
|
||||
|
||||
--- Global environment setup.
|
||||
-- The following assignments expose core utilities globally,
|
||||
-- making them accessible in all subsequently loaded modules.
|
||||
|
||||
_ENV.cLib = cLib ~= nil and cLib or export.community_lib.cLib() ---@type table
|
||||
_ENV.Require = Require ---@type fun(module: string): any
|
||||
exports("RegisterModule", Bridge.RegisterModule)
|
||||
|
||||
--TODO: Create a way to overide functions or create a new functions for module
|
||||
|
||||
@@ -87,8 +87,6 @@ local function getSharedLib()
|
||||
end
|
||||
|
||||
cLib = setmetatable(getSharedLib(), { __index = IsDuplicityVersion() and getServerLib() or getClientLib() })
|
||||
_ENV.cLib = cLib
|
||||
_ENV.Require = Require
|
||||
exports('cLib', function()
|
||||
return cLib
|
||||
end)
|
||||
|
||||
Reference in new issue
Block a user