refactor: localise globals to prevent shadowing

See #456.
This commit is contained in:
Linden
2023-12-07 08:36:40 +11:00
parent 62ff7345b9
commit aebe248e39
3 changed files with 10 additions and 4 deletions

View File

@@ -15,7 +15,8 @@ local glm = require 'glm'
---@field [string] any ---@field [string] any
---@type table<number, CZone> ---@type table<number, CZone>
Zones = {} local Zones = {}
_ENV.Zones = Zones
local function nextFreePoint(points, b, len) local function nextFreePoint(points, b, len)
for i = 1, len do for i = 1, len do

View File

@@ -1,7 +1,8 @@
local glm = require 'glm' local glm = require 'glm'
---@type table<number, CZone> ---@type table<number, CZone>
Zones = {} local Zones = {}
_ENV.Zones = Zones
local function removeZone(self) local function removeZone(self)
Zones[self.id] = nil Zones[self.id] = nil

View File

@@ -84,7 +84,7 @@ local function call(self, index, ...)
return module return module
end end
lib = setmetatable({ local lib = setmetatable({
name = ox_lib, name = ox_lib,
context = context, context = context,
onCache = function(key, cb) onCache = function(key, cb)
@@ -95,6 +95,8 @@ lib = setmetatable({
__call = call, __call = call,
}) })
_ENV.lib = lib
-- Override standard Lua require with our own. -- Override standard Lua require with our own.
require = lib.require require = lib.require
@@ -167,7 +169,7 @@ end
---Caches the result of a function, optionally clearing it after timeout ms. ---Caches the result of a function, optionally clearing it after timeout ms.
function cache(key, func, timeout) end function cache(key, func, timeout) end
cache = setmetatable({ game = GetGameName(), resource = resourceName }, { local cache = setmetatable({ game = GetGameName(), resource = resourceName }, {
__index = context == 'client' and function(self, key) __index = context == 'client' and function(self, key)
AddEventHandler(('ox_lib:cache:%s'):format(key), function(value) AddEventHandler(('ox_lib:cache:%s'):format(key), function(value)
self[key] = value self[key] = value
@@ -191,6 +193,8 @@ cache = setmetatable({ game = GetGameName(), resource = resourceName }, {
end, end,
}) })
_ENV.cache = cache
local notifyEvent = ('__ox_notify_%s'):format(cache.resource) local notifyEvent = ('__ox_notify_%s'):format(cache.resource)
if context == 'client' then if context == 'client' then