fix list handling, add puketh

This commit is contained in:
Kistaro Windrider 2023-09-30 13:59:07 -07:00
parent cb65a188a8
commit 8fb54ede26
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -296,11 +296,11 @@ end
-- default). used for table -- default). used for table
-- debugging. table-type keys -- debugging. table-type keys
-- are not legible here -- are not legible here
function puke(item, indent, seen) function puke(item, indent, seen, hidekey)
if (type(item) ~= "table") return tostr(item) if (type(item) ~= "table") return tostr(item)
seen = seen or {} seen = seen or {}
if (seen[item]) return "<<PREV>>" if (seen[item]) return "<<...>>"
seen[item] = true seen[item] = true
indent = indent or 0 indent = indent or 0
@ -313,20 +313,23 @@ function puke(item, indent, seen)
local ret,n = "linked_list <",0 local ret,n = "linked_list <",0
item:strip(function(x) item:strip(function(x)
n += 1 n += 1
local masked_x = {next="<<...>>"} ret ..= pfx..tostr(n)..": "..puke(x, indent+1, seen, "next")
setmetatable(masked_x, {__index=x})
ret ..= pfx..tostr(n)..": "..masked_x
end) end)
return ret..pfx..">" return ret..pfx..">"
end end
local ret = "{" local ret = "{"
for k, v in pairs(item) do for k, v in pairs(item) do
ret ..= pfx..tostr(k)..": "..puke(v, indent+1, seen) if (k ~= hidekey) ret ..= pfx..tostr(k)..": "..puke(v, indent+1, seen)
end end
return ret..pfx.."}" return ret..pfx.."}"
end end
-- convenience for debugging
function puketh(item)
printh(puke(item))
end
function drawgame() function drawgame()
cls() cls()
clip(0,0,112,128) clip(0,0,112,128)