int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
Returns information about a specific function or function invocation.
To get information about a function invocation, the parameter ar must be a valid activation record that was filled by a previous call to lua_getstack or given as argument to a hook (see lua_Hook).
To get information about a function you push it onto the stack and start the what string with the character '=>='. (In that case, lua_getinfo pops the function in the top of the stack.) For instance, to know in which line a function f was defined, you can write the following code:
lua_Debug ar;
lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global 'f' */
lua_getinfo(L, ">S", &ar);
printf("%d\n", ar.linedefined);
Each character in the string what selects some fields of the structure ar to be filled or a value to be pushed on the stack:
name and namewhat;
source, short_src, linedefined, lastlinedefined, and what;
currentline;
nups;
This function returns 0 on error (for instance, an invalid option in what).