lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> Another solution, much more straightforward, would be that LUA had
> something equivalent to lua_pushupvalues() in its API, but instead of
> reading the upvalues of the current call frame, being able to get the
> upvalues of a cclosure at a given stack index.

Lua 5.0 final will have functions to manipulate upvalues, as part of its
debug API:

LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);

Both operate on the function `funcindex' (which may be a Lua function or
a C function). lua_getupvalue pushes the upvalue, lua_setupvalue pops
a value and updates the upvalue. Both return the name of the upvalue (for
Lua functions), "" for C functions, and NULL if the function does not
have a n-th upvalue.

-- Roberto