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:
SquidDev 2020-11-27 21:29:11 +00:00
parent 486f41f082
commit 04f9644ae7
2 changed files with 6 additions and 4 deletions

View File

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

View File

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