Skip to content

Commit

Permalink
fix(core): Use nil-safe and Lua-version-robust table utils
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Dec 8, 2023
1 parent ff40938 commit 2405b23
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/cli.lua
Expand Up @@ -108,7 +108,7 @@ cli.parseArguments = function ()
-- http://lua-users.org/wiki/VarargTheSecondClassCitizen
local summary = function (...)
local contentloc = SILE.traceStack:locationHead()
local codeloc = table.unpack({...}, 1, select('#', ...))
local codeloc = pl.utils.unpack({...}, 1, select('#', ...))
return ("Processing at: %s\n\tUsing code at: %s"):format(contentloc, codeloc)
end
local unexpected = function ()
Expand Down
2 changes: 1 addition & 1 deletion core/deprecations.lua
Expand Up @@ -30,7 +30,7 @@ SILE.fluent = setmetatable({}, {
__call = function (_, ...)
fluentglobal()
SILE.fluent = fluent
return fluent(table.unpack({...}, 1, select("#", ...)))
return fluent(pl.utils.unpack({...}, 1, select("#", ...)))
end,
__index = function (_, key)
fluentglobal()
Expand Down
4 changes: 2 additions & 2 deletions core/utilities.lua
Expand Up @@ -115,7 +115,7 @@ end
utilities.debug = function (category, ...)
if SILE.quiet then return end
if utilities.debugging(category) then
local inputs = table.pack(...)
local inputs = pl.utils.pack(...)
for i, input in ipairs(inputs) do
if type(input) == "function" then
local status, output = pcall(input)
Expand Down Expand Up @@ -261,7 +261,7 @@ end

utilities.compress = function (items)
local rv = {}
local max = math.max(table.unpack(pl.tablex.keys(items)))
local max = math.max(pl.utils.unpack(pl.tablex.keys(items)))
for i = 1, max do if items[i] then rv[#rv+1] = items[i] end end
return rv
end
Expand Down
2 changes: 1 addition & 1 deletion outputters/debug.lua
Expand Up @@ -44,7 +44,7 @@ end

function outputter:_writeline (...)
self:_ensureInit()
local args = table.pack(...)
local args = pl.utils.pack(...)
for i = 1, #args do
outfile:write(args[i])
if i < #args then outfile:write("\t") end
Expand Down
2 changes: 1 addition & 1 deletion outputters/text.lua
Expand Up @@ -23,7 +23,7 @@ end

function outputter:_writeline (...)
self:_ensureInit()
local args = table.pack(...)
local args = pl.utils.pack(...)
for i=1, #args do
outfile:write(args[i])
end
Expand Down
4 changes: 2 additions & 2 deletions packages/base.lua
Expand Up @@ -81,7 +81,7 @@ function package:deprecatedExport (name, func, noclass, notable)
SU.deprecated(("class.%s"):format(name),
("class.packages.%s:%s"):format(self._name, name),
"0.14.0", "0.16.0", _deprecate_class_funcs)
return func(table.unpack(inputs, 1, select("#", ...) + 1))
return func(pl.utils.unpack(inputs, 1, select("#", ...) + 1))
end
end

Expand All @@ -94,7 +94,7 @@ function package:deprecatedExport (name, func, noclass, notable)
SU.deprecated(("require('packages.%s').exports.%s"):format(self._name, name),
("class.packages.%s:%s"):format(self._name, name),
"0.14.0", "0.16.0", _deprecate_exports_table)
return func(table.unpack(inputs, 1, select("#", ...) + 1))
return func(pl.utils.unpack(inputs, 1, select("#", ...) + 1))
end
end

Expand Down
2 changes: 1 addition & 1 deletion packages/math/base-elements.lua
Expand Up @@ -1112,7 +1112,7 @@ function elements.table:_init (children, options)
self.children = children
self.options = options
self.nrows = #self.children
self.ncols = math.max(table.unpack(mapList(function(_, row)
self.ncols = math.max(pl.utils.unpack(mapList(function(_, row)
return #row.children end, self.children)))
SU.debug("math", "self.ncols =", self.ncols)
self.rowspacing = self.options.rowspacing and SILE.length(self.options.rowspacing)
Expand Down
2 changes: 1 addition & 1 deletion packages/math/texlike.lua
Expand Up @@ -83,7 +83,7 @@ local mathGrammar = function (_ENV)
-- Remove the last mathlist if empty. This way,
-- `inner1 \\ inner2 \\` is the same as `inner1 \\ inner2`.
if not t[#t][1] or not t[#t][1][1] then table.remove(t) end
return table.unpack(t)
return pl.utils.unpack(t)
end

START "texlike_math"
Expand Down

0 comments on commit 2405b23

Please sign in to comment.