From 68aa645494d27f9dde8522a58b01afea687d9d26 Mon Sep 17 00:00:00 2001 From: JericoFX Date: Mon, 12 May 2025 12:13:16 -0300 Subject: [PATCH] Refactor global environment setup by removing redundant assignments to _ENV --- init.lua | 14 +++++++++++++- lib/init.lua | 2 -- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index d9818c8..6a1c9cc 100644 --- a/init.lua +++ b/init.lua @@ -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 diff --git a/lib/init.lua b/lib/init.lua index 9db3466..4003b66 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -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)