From 717686d85539e53d01d529d022217c25e45e35fb Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Fri, 7 May 2021 11:26:24 -0700 Subject: [PATCH] Allow strings or numbers in textutils.*tabulate 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 --- patchwork.md | 12 ++++++++++++ .../data/computercraft/lua/rom/apis/textutils.lua | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/patchwork.md b/patchwork.md index 8e621ce2b..910d99b2f 100644 --- a/patchwork.md +++ b/patchwork.md @@ -362,3 +362,15 @@ Remove extra space (#586) Fixed length check on function name in `expect` (#589) ``` + +``` +04f9644ae75dafc72da4c4790f334d2e90b03e6f + +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 +``` 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 a55991fc9..c80f8c3c9 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