Skip to content

Commit

Permalink
address type warnings caused by Lua5.1 and 5.2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CogentRedTester committed Feb 22, 2025
1 parent d986d11 commit 4d026e2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions modules/addons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ local function run_addon(path)
end

local chunk, err
if setfenv then
if setfenv then ---@diagnostic disable-line deprecated
--since I stupidly named a function loadfile I need to specify the global one
--I've been using the name too long to want to change it now
chunk, err = _G.loadfile(path)
if not chunk then return msg.error(err) end
setfenv(chunk, addon_environment)
setfenv(chunk, addon_environment) ---@diagnostic disable-line deprecated
else
chunk, err = _G.loadfile(path, "bt", addon_environment)
chunk, err = _G.loadfile(path, "bt", addon_environment) ---@diagnostic disable-line redundant-parameter
if not chunk then return msg.error(err) end
end

Expand Down
2 changes: 1 addition & 1 deletion modules/apis/parse-state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function parse_state_API:yield(...)
msg.verbose("browser no longer waiting for list - aborting parse for", self.directory)
error(g.ABORT_ERROR)
end
return unpack(result, 1, result.n)
return table.unpack(result, 1, result.n)
end

---Checks if the current coroutine is the one handling the browser's request.
Expand Down
12 changes: 6 additions & 6 deletions modules/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fb_utils.coroutine = {}

--implements table.pack if on lua 5.1
if not table.pack then
table.unpack = unpack
table.unpack = unpack ---@diagnostic disable-line deprecated
---@diagnostic disable-next-line: duplicate-set-field
function table.pack(...)
local t = {n = select("#", ...), ...}
Expand Down Expand Up @@ -504,11 +504,11 @@ function fb_utils.evaluate_string(str, chunkname, custom_env, env_defaults)
end

local chunk, err
if setfenv then
chunk, err = loadstring(str, chunkname)
if chunk then setfenv(chunk, env) end
if setfenv then ---@diagnostic disable-line deprecated
chunk, err = loadstring(str, chunkname) ---@diagnostic disable-line deprecated
if chunk then setfenv(chunk, env) end ---@diagnostic disable-line deprecated
else
chunk, err = load(str, chunkname, 't', env)
chunk, err = load(str, chunkname, 't', env) ---@diagnostic disable-line redundant-parameter
end
if not chunk then
msg.warn('failed to load string:', str)
Expand Down Expand Up @@ -563,7 +563,7 @@ fb_utils.code_fns = {
i = function(item, s)
local i = fb_utils.list.indexOf(s.list, item)
if #s.list == 0 then return 0 end
return ('%0'..math.ceil(math.log10(#s.list))..'d'):format(i ~= -1 and i or 0)
return ('%0'..math.ceil(math.log(#s.list, 10))..'d'):format(i ~= -1 and i or 0)
end,
j = function (item, s)
return fb_utils.list.indexOf(s.list, item) ~= -1 and math.abs(fb_utils.list.indexOf( fb_utils.sort_keys(s.selection) , item)) or 0
Expand Down

0 comments on commit 4d026e2

Please sign in to comment.