mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 11:40:29 +00:00
Allow strings or numbers in textutils.*tabulate
A little dubious, but apparently CC used to support it. This means we're consistent with methods like io.write or string.len which accept strings or numbers. Fixes #591
This commit is contained in:
parent
486f41f082
commit
04f9644ae7
@ -163,10 +163,11 @@ local function tabulateCommon(bPaged, ...)
|
||||
for n, t in ipairs(tAll) do
|
||||
if type(t) == "table" then
|
||||
for nu, sItem in pairs(t) do
|
||||
if type(sItem) ~= "string" then
|
||||
error("bad argument #" .. n .. "." .. nu .. " (expected string, got " .. type(sItem) .. ")", 3)
|
||||
local ty = type(sItem)
|
||||
if ty ~= "string" and ty ~= "number" then
|
||||
error("bad argument #" .. n .. "." .. nu .. " (expected string, got " .. ty .. ")", 3)
|
||||
end
|
||||
nMaxLen = math.max(#sItem + 1, nMaxLen)
|
||||
nMaxLen = math.max(#tostring(sItem) + 1, nMaxLen)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -33,11 +33,12 @@ describe("The textutils library", function()
|
||||
term.redirect(window.create(term.current(), 1, 1, 5, 5, false))
|
||||
|
||||
textutils.tabulate()
|
||||
textutils.tabulate({ "test" })
|
||||
textutils.tabulate({ "test", 1 })
|
||||
textutils.tabulate(colors.white)
|
||||
|
||||
expect.error(textutils.tabulate, nil):eq("bad argument #1 (expected number or table, got nil)")
|
||||
expect.error(textutils.tabulate, { "test" }, nil):eq("bad argument #2 (expected number or table, got nil)")
|
||||
expect.error(textutils.tabulate, { false }):eq("bad argument #1.1 (expected string, got boolean)")
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user