diff --git a/updatedshmup.p8 b/updatedshmup.p8 index b7c506a..6dc99a4 100644 --- a/updatedshmup.p8 +++ b/updatedshmup.p8 @@ -45,7 +45,9 @@ function mknew(tt, more) end end -linked_list = {} +-- intrusive singly-linked list. +-- cannot be nested! +linked_list = {is_linked_list=true} mknew(linked_list, function(x) x.next=nil x.tail=x @@ -288,17 +290,39 @@ function fadescreen() end end -function puke(item, indent) +-- puke emits a verbose string +-- describing item, indented to +-- the specified depth (0 by +-- default). used for table +-- debugging. table-type keys +-- are not legible here +function puke(item, indent, seen) + if (type(item) ~= "table") return tostr(item) + + seen = seen or {} + if (seen[item]) return "<>" + seen[item] = true + indent = indent or 0 - local pfx = "" + local pfx = "\n" for _=1,indent do pfx ..= " " end - if (type(item) ~= "table") return pfx..tostr(item) - ret = pfx.."{" - pfx = "\n"..pfx + + if item.is_linked_list then + local ret,n = "linked_list <",0 + item:strip(function(x) + n += 1 + local masked_x = {next="<<...>>"} + setmetatable(masked_x, {__index=x}) + ret ..= pfx..tostr(n)..": "..masked_x + end) + return ret..pfx..">" + end + + local ret = "{" for k, v := pairs(item) do - ret ..= pfx..tostr(k)..": "..puke(v, indent+1) + ret ..= pfx..tostr(k)..": "..puke(v, indent+1, seen) end return ret..pfx.."}" end