*lua_getinfo()*
>c
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` (see |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:
>c
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:
`'n'` fills in the field `name` and `namewhat`
`'S'` fills in the fields `source`, `short_src`, `linedefined`,
`lastlinedefined`, and `what`
`'l'` fills in the field `currentline`
`'u'` fills in the field `nups`
`'f'` pushes onto the stack the function that is running at the
given level
`'L'` pushes onto the stack a table whose indices are the numbers
of the lines that are valid on the function. (A `valid line` is a
line with some associated code, that is, a line where you can put
a break point. Non-valid lines include empty lines and comments.)
This function returns 0 on error (for instance, an invalid option in
`what`).
lua_getlocal *lua_getlocal()*
>c
const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);
<
Gets information about a local variable of a given activation record.
The parameter `ar` must be a valid activation record that was filled
by a previous call to `lua_getstack` (see |lua_getstack()|) or
given as argument to a hook (see |lua_Hook|). The index `n`
selects which local variable to inspect (1 is the first parameter or
active local variable, and so on, until the last active local
variable). `lua_getlocal` pushes the variable's value onto the stack
and returns its name.
Variable names starting with `(` (open parentheses) represent
internal variables (loop control variables, temporaries, and C
function locals).
Returns `NULL` (and pushes nothing) when the index is greater than the
number of active local variables.
lua_getstack *lua_getstack()*
>c
int lua_getstack (lua_State *L, int level, lua_Debug *ar);
<
Gets information about the interpreter runtime stack.
This function fills parts of a `lua_Debug` (see |lua_Debug|)
structure with an identification of the `activation record` of the
function executing at a given level. Level 0 is the current running
function, whereas level `n+1` is the function that has called level
`n`. When there are no errors, `lua_getstack` returns 1; when called
with a level greater than the stack depth, it returns 0.
lua_getupvalue *lua_getupvalue()*
>c
const char *lua_getupvalue (lua_State *L, int funcindex, int n);
<
Gets information about a closure's upvalue. (For Lua functions,
upvalues are the external local variables that the function uses, and
that are consequently included in its closure.) `lua_getupvalue` gets
the index `n` of an upvalue, pushes the upvalue's value onto