|
Am 03.12.2013 02:00 schröbte Andrew Starks:
On Monday, December 2, 2013, Sean Conner wrote:It was thus said that the Great Andrew Starks once stated:Given the following: ``` int iter(lua_State *L){ ///what to do here? lua_pushinteger(L, (lua_Integer) luaL_checkint(L, lua_upvalueindex(1)) + 1); //I can get the upvalue... // how do I set it? //lua_getupvalue (lua_State *L, int funcindex, int n); //doesn't seem like the correct function because iter is not on the stack, at this point. } int factory(lua_State *L){ lua_pushnumber(L, 0); lua_pushcclosure(L, iter, 1); return 1; } ```You want to call ua_upvalueindex(). That will return an index you can pass to other Lua functions that take an index. It's described in section 3.4 of Lua 5.1 and section 4.4 of Lua 5.2. -spcI messed up. It's setupvalue not get.
That may be true, but given your description you probably wanted `lua_replace(L, lua_upvalueindex(1))` anyway as Sean suggested (sort of) ...
-Andrew
Philipp