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

7.1 Stack and Function Information

The main function to get information about the interpreter stack is

lua_Function lua_stackedfunction (int level);
It returns a handle (lua_Function ) to the activation record of the function executing at a given level. Level 0 is the current running function, while level n+1 is the function that has called level n. When called with a level greater than the stack depth, lua_stackedfunction returns LUA_NOOBJECT .

The type lua_Function is just another name to lua_Object . Although, in this library, a lua_Function can be used wherever a lua_Object is required, a parameter lua_Function accepts only a handle returned by lua_stackedfunction .

Three other functions produce extra information about a function:

void lua_funcinfo (lua_Object func, char **filename, int *linedefined);
int lua_currentline (lua_Function func);
char *lua_getobjname (lua_Object o, char **name);
lua_funcinfo gives the file name and the line where the given function has been defined. If the ``function'' is in fact the main code of a chunk, linedefined is 0. If the function is a C function, linedefined is -1, and filename is "(C)" .

The function lua_currentline gives the current line where a given function is executing. It only works if the function has been pre-compiled with debug information (see Section 4.8). When no line information is available, it returns -1.

Function lua_getobjname tries to find a reasonable name for a given function. Because functions in Lua are first class values, they do not have a fixed name. Some functions may be the value of many global variables, while others may be stored only in a table field. Function lua_getobjname first checks whether the given function is a fallback. If so, it returns the string "fallback" , and name is set to point to the fallback name. Otherwise, if the given function is the value of a global variable, lua_getobjname returns the string "global" , while name points to the variable name. If the given function is neither a fallback nor a global variable, lua_getobjname returns the empty string, and name is set to NULL .


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