/* (S) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
other fields
} lua_Debug;
<
A structure used to carry different pieces of information about an active
function. `lua_getstack` (see |lua_getstack()|) fills only the private part
of this structure, for later use. To fill the other fields of `lua_Debug` with
useful information, call `lua_getinfo` (see |lua_getinfo()|).
The fields of `lua_Debug` have the following meaning:
- `source` If the function was defined in a string, then `source` is
that string. If the function was defined in a file, then
`source` starts with a `@` followed by the file name.
- `short_src` a "printable" version of `source`, to be used in error messages.
- `linedefined` the line number where the definition of the function starts.
- `lastlinedefined` the line number where the definition of the function ends.
- `what` the string `"Lua"` if the function is a Lua function,
`"C"` if it is a C function, `"main"` if it is the main
part of a chunk, and `"tail"` if it was a function that
did a tail call. In the latter case, Lua has no other
information about the function.
- `currentline` the current line where the given function is executing.
When no line information is available, `currentline` is
set to -1.
- `name` a reasonable name for the given function. Because
functions in Lua are first-class values, they do not have
a fixed name: some functions may be the value of multiple
global variables, while others may be stored only in a
table field. The `lua_getinfo` function checks how the
function was called to find a suitable name. If it cannot
find a name, then `name` is set to `NULL`.
- `namewhat` explains the `name` field. The value of `namewhat` can be
`"global"`, `"local"`, `"method"`, `"field"`,
`"upvalue"`, or `""` (the empty string), according to how
the function was called. (Lua uses the empty string when
no other option seems to apply.) `nups` the number of
upvalues of the function.
lua_gethook *lua_gethook()*
>c
lua_Hook lua_gethook (lua_State *L);
<
Returns the current hook function.
lua_gethookcount *lua_gethookcount()*
>c
int lua_gethookcount (lua_State *L);
<
Returns the current hook count.
lua_gethookmask *lua_gethookmask()*
>c
int lua_gethookmask (lua_State *L);
<
Returns the current hook mask.
lua_getinfo *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);
<