refactor(init): don't cache function refs

This commit is contained in:
Linden
2022-02-28 08:35:32 +11:00
parent 02ba40124e
commit 40b7fe2a77
2 changed files with 10 additions and 11 deletions

View File

@@ -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.'

View File

@@ -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