Hooks

Lua provides hooks to monitor an application running in real time. An event handler function can be registered to be executed every time an event or hook happens. There are four types of events that can be hooked into:

  • line: called every time a line of code is executed
  • call: called every time a new function is called
  • return: called every time a function returns
  • counter: called every x number of instructions, where the caller specifies x.

To register for line, call or return, call debug.sethook with a handler function and the first letter of the event being hooked into. For example, registering for call events would look like this: debug.sethoof(function, "c"). The event handler function should take one argument in all cases, except for the line event, when it should take two. The first argument will always be a string describing the event. The optional second argument for line will be the line number being executed.

Once a hook has been set, it can be cleared by calling the debug.sethook function with no arguments.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.235.176