`LUA_MASKCOUNT`. The `count` argument is only meaningful when the mask
includes `LUA_MASKCOUNT`. For each event, the hook is called as
explained below:
- `The call hook`: is called when the interpreter calls a function.
The hook is called just after Lua enters the new function, before
the function gets its arguments.
- `The return hook`: is called when the interpreter returns from a
function. The hook is called just before Lua leaves the function.
You have no access to the values to be returned by the function.
- `The line hook`: is called when the interpreter is about to start
the execution of a new line of code, or when it jumps back in the
code (even to the same line). (This event only happens while Lua is
executing a Lua function.)
- `The count hook`: is called after the interpreter executes every
`count` instructions. (This event only happens while Lua is
executing a Lua function.)
A hook is disabled by setting `mask` to zero.
lua_setlocal *lua_setlocal()*
>c
const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);
<
Sets the value of a local variable of a given activation record.
Parameters `ar` and `n` are as in `lua_getlocal` (see
|lua_getlocal()|). `lua_setlocal` assigns the value at the top of
the stack to the variable and returns its name. It also pops the value
from the stack.
Returns `NULL` (and pops nothing) when the index is greater than the
number of active local variables.
lua_setupvalue *lua_setupvalue()*
>c
const char *lua_setupvalue (lua_State *L, int funcindex, int n);
<
Sets the value of a closure's upvalue. It assigns the value at the top
of the stack to the upvalue and returns its name. It also pops the
value from the stack. Parameters `funcindex` and `n` are as in the
`lua_getupvalue` (see |lua_getupvalue()|).
Returns `NULL` (and pops nothing) when the index is greater than the
number of upvalues.
*lua-debugexample*
As an example, the following function lists the names of all local
variables and upvalues for a function at a given level of the stack:
>c
int listvars (lua_State *L, int level) {
lua_Debug ar;
int i;
const char *name;
if (lua_getstack(L, level, &ar) == 0)
return 0; /* failure: no such level in the stack */
i = 1;
while ((name = lua_getlocal(L, &ar, i++)) != NULL) {
printf("local %d %s\n", i-1, name);
lua_pop(L, 1); /* remove variable value */
}
lua_getinfo(L, "f", &ar); /* retrieves function */
i = 1;
while ((name = lua_getupvalue(L, -1, i++)) != NULL) {
printf("upvalue %d %s\n", i-1, name);
lua_pop(L, 1); /* remove upvalue value */
}
return 1;
}
<
==============================================================================
4 THE AUXILIARY LIBRARY *lua-aux*
The auxiliary library provides several convenient functions to interface C
with Lua. While the basic API provides the primitive functions for all
interactions between C and Lua, the auxiliary library provides higher-level
functions for some common tasks.
All functions from the auxiliary library are defined in header file `lauxlib.h`
and have a prefix `luaL_`.
All functions in the auxiliary library are built on top of the basic API, and
so they provide nothing that cannot be done with this API.
Several functions