Next: 8 Some Examples Up: 7 The Debuger Interface Previous: 7.2 Manipulating Local Variables

7.3 Hooks

The Lua interpreter offers two hooks for debug purposes:

typedef void (*lua_CHFunction) (lua_Function func, char *file, int line);
extern lua_CHFunction lua_callhook;

typedef void (*lua_LHFunction) (int line);
extern lua_LHFunction lua_linehook;
The first one is called whenever the interpreter enters or leaves a function. When entering a function, its parameters are a handle to the function activation record, plus the file and the line where the function is defined (the same information which is provided by lua_funcinfo ); when leaving a function, func is LUA_NOOBJECT , file is "(return)" , and line is 0.

The other hook is called every time the interpreter changes the line of code it is executing. Its only parameter is the line number (the same information which is provided by the call lua_currentline(lua_stackedfunction(0)) ). This second hook is only called if the active function has been pre-compiled with debug information (see Section 4.8).

A hook is disabled when its value is NULL (0), which is the initial value of both hooks.


Next: 8 Some Examples Up: 7 The Debuger Interface Previous: 7.2 Manipulating Local Variables