July 2018
Beginner
202 pages
5h 42m
English
Multiple hooks can be specified by adding a space and another letter to debug.sethook. For example, you could subscribe to every possible event, like so:
debug.sethook(trace, "l c r", 1)
When subscribing to multiple hooks, remember the callback's second argument is nil, except for the line event. Check for nil as appropriate. The following code demonstrates how to do this:
function trace(event, line) local info = debug.getinfo(2) if info.what == "Lua" then print ("event: " .. event) print (" function: " .. info.name) print (" defined on: " .. info.linedefined) if line ~= nil then print (" called from: " .. line) end endend