Next: 7.3 Hooks Up: 7 The Debuger Interface Previous: 7.1 Stack and Function

7.2 Manipulating Local Variables

The following functions allow the manipulation of the local variables of a given activation record. They only work if the function has been pre-compiled with debug information (see Section 4.8).

lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
int lua_setlocal (lua_Function func, int local_number);
The first one returns the value of a local variable, and sets name to point to the variable name. local_number is an index for local variables. The first parameter has index 1, and so on, until the last active local variable. When called with a local_number greater than the number of active local variables, or if the activation record has no debug information, lua_getlocal returns LUA_NOOBJECT .

The function lua_setlocal sets the local variable local_number to the value previously pushed on the stack (see Section 5.2). If the function succeeds it returns 1. If local_number is greater than the number of active local variables, or if the activation record has no debug information, this function fails and returns 0.


Next: 7.3 Hooks Up: 7 The Debuger Interface Previous: 7.1 Stack and Function