lua-users home
lua-l archive

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


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;
}

```

My question is, how do you change the value of an upvalue when you are
in the C closure that has the upvalue? You can get it, but how does
one set it? I didn't see a pseudo index for it.

I'm sure I'm missing something really basic.

Thanks!

-Andrew