From ece5490fd95625049a8696c8d0d6aa08e1e5a12f Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 17 Nov 2019 13:57:36 -0500 Subject: [PATCH] Improve ilua's table output for tables that have both an array part and additional keys Previously for such tables it would just show the array part and ignore the rest. --- data/lua/ilua.lua | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/data/lua/ilua.lua b/data/lua/ilua.lua index 88e14a6f6f74..2e494945e2a3 100644 --- a/data/lua/ilua.lua +++ b/data/lua/ilua.lua @@ -9,7 +9,6 @@ local pretty_print_limit = 20 local max_depth = 7 -local table_clever = true -- imported global functions local sub = string.sub @@ -39,15 +38,7 @@ function ilua.join(tbl,delim,limit,depth) end end push(jstack,tbl) - -- this is a hack to work out if a table is 'list-like' or 'map-like' - -- you can switch it off with ilua.table_options {clever = false} - local is_list - if table_clever then - local index1 = n > 0 and tbl[1] - local index2 = n > 1 and tbl[2] - is_list = index1 and index2 - end - if is_list then + if n > 0 then for i,v in ipairs(tbl) do res = res..delim..ilua.val2str(v) k = k + 1 @@ -56,20 +47,21 @@ function ilua.join(tbl,delim,limit,depth) break end end - else - for key,v in pairs(tbl) do - if type(key) == 'number' then - key = '['..tostring(key)..']' - else - key = tostring(key) - end - res = res..delim..key..'='..ilua.val2str(v) - k = k + 1 - if k > limit then - res = res.." ... " - break - end + end + for key,v in pairs(tbl) do + if type(key) == 'number' then + if key <= n then goto continue end + key = '['..tostring(key)..']' + else + key = tostring(key) + end + res = res..delim..key..'='..ilua.val2str(v) + k = k + 1 + if k > limit then + res = res.." ... " + break end + ::continue:: end pop(jstack) return sub(res,2) @@ -92,6 +84,8 @@ function ilua.val2str(val) else return '{'..ilua.join(val,',')..'}' end + --elseif tp == 'userdata' then + elseif tp == 'string' then return "'"..val.."'" elseif tp == 'number' then