diff --git a/src/main/resources/data/computercraft/lua/rom/apis/textutils.lua b/src/main/resources/data/computercraft/lua/rom/apis/textutils.lua index ec0633589..30766e8ec 100644 --- a/src/main/resources/data/computercraft/lua/rom/apis/textutils.lua +++ b/src/main/resources/data/computercraft/lua/rom/apis/textutils.lua @@ -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 diff --git a/src/test/resources/test-rom/spec/apis/textutils_spec.lua b/src/test/resources/test-rom/spec/apis/textutils_spec.lua index 486bf6118..6db7917ea 100644 --- a/src/test/resources/test-rom/spec/apis/textutils_spec.lua +++ b/src/test/resources/test-rom/spec/apis/textutils_spec.lua @@ -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)