Skip to content

Commit

Permalink
Improve ilua's table output for tables that have both an array part a…
Browse files Browse the repository at this point in the history
…nd additional keys

Previously for such tables it would just show the array part and ignore the rest.
  • Loading branch information
CelticMinstrel committed Nov 17, 2019
1 parent 61d0da9 commit ece5490
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions data/lua/ilua.lua
Expand Up @@ -9,7 +9,6 @@

local pretty_print_limit = 20
local max_depth = 7
local table_clever = true

-- imported global functions
local sub = string.sub
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ece5490

Please sign in to comment.