about summary refs log tree commit diff stats
path: root/hanoi.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-11 22:05:15 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-11 22:05:15 -0800
commit49a09cceeca34794361d02c30530a754013a5c17 (patch)
tree2122beff1753f243b7c2ebd297286b7d6a7735d0 /hanoi.lua
parentd72eae59784e8da00c7fe00539b1095e1f8ccaf4 (diff)
downloadteliva-49a09cceeca34794361d02c30530a754013a5c17.tar.gz
learning about Lua's debug infrastructure
https://www.lua.org/pil/23.2.html
Diffstat (limited to 'hanoi.lua')
-rw-r--r--hanoi.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/hanoi.lua b/hanoi.lua
index 78cf1c5..2284f7b 100644
--- a/hanoi.lua
+++ b/hanoi.lua
@@ -1,5 +1,18 @@
 curses = require "curses"
 
+count = {}
+function foo(event, line)
+  local s = debug.getinfo(2)
+--?   print(s.name)
+  if s.name ~= nil then
+    if count[s.name] == nil then
+      count[s.name] = 0
+    end
+    count[s.name] = count[s.name]+1
+  end
+end
+debug.sethook(foo, "c")
+
 window = curses.initscr()
 
 tower = {{6, 5, 4, 3, 2}, {}, {}}
@@ -54,6 +67,14 @@ function render_tower(window, line, col, tower_index, tower)
     window:attroff(curses.color_pair(7))
     line = line - 1
   end
+
+  window:mvaddstr(30, 0, "profile: ")
+  for k,v in pairs(count) do
+    window:addstr(k)
+    window:addstr(": ")
+    window:addstr(v)
+    window:addstr("; ")
+  end
 end
 
 function render(window)