Sets a debug hook function
Sets the function f as a hook to be called when the "mask" condition is satisfied.
c - called every time Lua calls a function
r - called every time Lua returns from a function
l - called every time Lua enters a new line of code
The mask can be the empty string if you simply want to hook after "count" instructions.
The function f is called with its first parameter being a string, which can be one of:
In the case of "line" events it gets a second parameter, being the new line number.
Inside the hook you can use debug.getinfo with level 2 to find information about the running function. (Level 0 is getinfo, and level 1 is the hook function). In the case of "tail return" however debug.getinfo will not return valid information.
Here is an example of setting a hook to stop a runaway function from executing for too long:
In this case, the hook stopped execution after 100 instructions.
This second example uses a "call" hook to display when each new function is entered:
See Also ...
debug.debug - Enters interactive debugging
Lua base functions
(Help topic: lua=debug.sethook)
Enter a search string to find matching documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.
Gammon Software support
Forum RSS feed ( https://gammon.com.au/rss/forum.xml )