Compare commits

...

5 Commits

Author SHA1 Message Date
a4bf3f616a
fix indentation when puking up a linked list 2023-09-30 14:00:53 -07:00
8fb54ede26
fix list handling, add puketh 2023-09-30 13:59:07 -07:00
cb65a188a8
lua is not go 2023-09-30 13:50:39 -07:00
7c29c329b7
handle backreferences and linked lists in puke 2023-09-30 13:50:07 -07:00
f67c2da37f
remove draw_debug since it doesn't work; add "puke" debug helper
linked lists don't have a measurable length. will use a persistent intangible for debug dumps in the future. `puke` however can be used at the CLI to dump a table. I need to write a `listpuke` variant too
2023-09-30 13:32:52 -07:00

View File

@ -9,8 +9,6 @@ game = 1
win = 2 win = 2
lose = 3 lose = 3
debug = {}
function usplit(str) function usplit(str)
return unpack(split(str)) return unpack(split(str))
end end
@ -47,7 +45,9 @@ function mknew(tt, more)
end end
end end
linked_list = {} -- intrusive singly-linked list.
-- cannot be nested!
linked_list = {is_linked_list=true}
mknew(linked_list, function(x) mknew(linked_list, function(x)
x.next=nil x.next=nil
x.tail=x x.tail=x
@ -251,7 +251,6 @@ end
function _draw() function _draw()
drawgame() drawgame()
draw_debug()
if (state == game) fadelvl = -45 if (state == game) fadelvl = -45
if (state == win) dropshadow("win",50,61,11) if (state == win) dropshadow("win",50,61,11)
if (state == lose) dropshadow("fail",48,61,8) if (state == lose) dropshadow("fail",48,61,8)
@ -291,21 +290,44 @@ function fadescreen()
end end
end end
function draw_debug() -- puke emits a verbose string
cursor(0,0,7) -- describing item, indented to
-- uncomment the followingh -- the specified depth (0 by
-- to display object counts -- default). used for table
--[[ -- debugging. table-type keys
print("es "..tostr(#eships)) -- are not legible here
print("eb "..tostr(#ebullets)) function puke(item, indent, seen, hidekey)
print("pb "..tostr(#pbullets)) if (type(item) ~= "table") return tostr(item)
print("ib "..tostr(#intangibles_bg))
print("if "..tostr(#intangibles_fg)) seen = seen or {}
print("v "..tostr(#events)) if (seen[item]) return "<<...>>"
]] seen[item] = true
if (#debug==0) return
foreach(debug,print) indent = indent or 0
debug={} local pfx = "\n"
for _=1,indent do
pfx ..= " "
end
if item.is_linked_list then
local ret,n,xpfx = "linked_list <",0,pfx.." "
item:strip(function(x)
n += 1
ret ..= xpfx..tostr(n)..": "..puke(x, indent+1, seen, "next")
end)
return ret..pfx..">"
end
local ret = "{"
for k, v in pairs(item) do
if (k ~= hidekey) ret ..= pfx..tostr(k)..": "..puke(v, indent+1, seen)
end
return ret..pfx.."}"
end
-- convenience for debugging
function puketh(item)
printh(puke(item))
end end
function drawgame() function drawgame()