diff options
author | sanine <sanine.not@pm.me> | 2022-08-18 20:52:26 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-08-18 20:52:26 -0500 |
commit | b8147afcc5bfbeb5fad62e4f68f1b88fc6c60d96 (patch) | |
tree | 8e5b63933b05a54bc2e74160fd2d53354a23f3d4 /libs/lua-5.1.5/test/trace-calls.lua | |
parent | de97d73a33ee3c1e2fe325b0cff90f079519bb36 (diff) |
add lua-5.1.5 files
Diffstat (limited to 'libs/lua-5.1.5/test/trace-calls.lua')
-rw-r--r-- | libs/lua-5.1.5/test/trace-calls.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libs/lua-5.1.5/test/trace-calls.lua b/libs/lua-5.1.5/test/trace-calls.lua new file mode 100644 index 0000000..6d7a7b3 --- /dev/null +++ b/libs/lua-5.1.5/test/trace-calls.lua @@ -0,0 +1,32 @@ +-- trace calls +-- example: lua -ltrace-calls bisect.lua + +local level=0 + +local function hook(event) + local t=debug.getinfo(3) + io.write(level," >>> ",string.rep(" ",level)) + if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end + t=debug.getinfo(2) + if event=="call" then + level=level+1 + else + level=level-1 if level<0 then level=0 end + end + if t.what=="main" then + if event=="call" then + io.write("begin ",t.short_src) + else + io.write("end ",t.short_src) + end + elseif t.what=="Lua" then +-- table.foreach(t,print) + io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">") + else + io.write(event," ",t.name or "(C)"," [",t.what,"] ") + end + io.write("\n") +end + +debug.sethook(hook,"cr") +level=0 |