The hook mechanism of the debug library allows us to register a function that will be called at specific events as your program runs. There are four kinds of events that can trigger a hook: call events happen every time Lua calls a function; return events happen every time a function returns; line events happen when Lua starts executing a new line of code; and count events happen after a given number of instructions. Lua calls hooks with a single argument, a string describing the event that generated the call: "call", "return", "line", or "count". Moreover, for line events, it also passes a second argument, the new line number. We can always use debug.getinfo to get more information inside a hook.
To register a hook, we call debug.sethook with two or three arguments: The first argument is the hook function; the second argument is a string that describes the events we want to monitor; and an optio
To register a hook, we call debug.sethook with two or three arguments: The first argument is the hook function; the second argument is a string that describes the events we want to monitor; and an optio