mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
refactor(init): don't cache function refs
This commit is contained in:
@@ -23,7 +23,7 @@ game 'gta5'
|
|||||||
--[[ Resource Information ]]--
|
--[[ Resource Information ]]--
|
||||||
name 'pe-lualib'
|
name 'pe-lualib'
|
||||||
author 'Linden'
|
author 'Linden'
|
||||||
version '1.3.0'
|
version '1.4.0'
|
||||||
repository 'https://github.com/project-error/pe-lualib'
|
repository 'https://github.com/project-error/pe-lualib'
|
||||||
description 'A library of shared functions to utilise in other resources.'
|
description 'A library of shared functions to utilise in other resources.'
|
||||||
|
|
||||||
|
|||||||
19
init.lua
19
init.lua
@@ -27,7 +27,7 @@ local function loadFile(self, module)
|
|||||||
|
|
||||||
if chunk then
|
if chunk then
|
||||||
local err
|
local err
|
||||||
chunk, err = load(chunk, ('@@pe-lualib/%s/%s.lua'):format(module, file), 't')
|
chunk, err = load(chunk, ('@@pe-lualib/%s/%s.lua'):format(module, file))
|
||||||
if err then
|
if err then
|
||||||
error(('\n^1Error importing module (%s): %s^0'):format(dir, err), 3)
|
error(('\n^1Error importing module (%s): %s^0'):format(dir, err), 3)
|
||||||
else
|
else
|
||||||
@@ -61,14 +61,13 @@ import = setmetatable({}, {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
lib = setmetatable({}, {
|
local export = exports[lualib]
|
||||||
__index = function(self, method)
|
|
||||||
local export = exports[lualib][method]
|
|
||||||
rawset(self, method, function(...)
|
|
||||||
return export(nil, ...)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return self[method]
|
lib = setmetatable({}, {
|
||||||
|
__index = function(_, method)
|
||||||
|
return function(...)
|
||||||
|
return export[method](nil, ...)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
__newindex = function()
|
__newindex = function()
|
||||||
@@ -87,7 +86,7 @@ local intervals = {}
|
|||||||
---@param ... any
|
---@param ... any
|
||||||
function SetInterval(callback, interval, ...)
|
function SetInterval(callback, interval, ...)
|
||||||
interval = interval or 0
|
interval = interval or 0
|
||||||
assert(type(interval) == 'number', ('Interval must be a number. Received %s'):format(tostring(interval)))
|
assert(type(interval) == 'number', ('Interval must be a number. Received %s'):format(json.encode(interval)))
|
||||||
local cbType = type(callback)
|
local cbType = type(callback)
|
||||||
|
|
||||||
if cbType == 'number' and intervals[callback] then
|
if cbType == 'number' and intervals[callback] then
|
||||||
@@ -114,7 +113,7 @@ function SetInterval(callback, interval, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ClearInterval(id)
|
function ClearInterval(id)
|
||||||
assert(type(id) == 'number', ('Interval id must be a number. Received %s'):format(tostring(id)))
|
assert(type(id) == 'number', ('Interval id must be a number. Received %s'):format(json.encode(id)))
|
||||||
assert(intervals[id], ('No interval exists with id %s'):format(id))
|
assert(intervals[id], ('No interval exists with id %s'):format(id))
|
||||||
intervals[id] = -1
|
intervals[id] = -1
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user