lua-users home
lua-l archive

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


Benoit Germain wrote: 
> 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.

Some time ago I posted:

LUA_API void lua_getupvalue (lua_State *L, int index, int upvalue) {
  StkId o;
  lua_lock(L);
  o = luaA_indexAcceptable(L, index);
  if( o==NULL || !iscfunction(o) )
    setnilvalue(L->top);
  else {
    Closure *cl = clvalue(o);
    if( upvalue<0 || upvalue >= cl->c.nupvalues )
      setnilvalue(L->top);
 else
      setobj(L->top, &cl->c.upvalue[upvalue]);
  }
  api_incr_top(L);
  lua_unlock(L);
}


Ignacio Castaño
castanyo@yahoo.es


___________________________________________________
Yahoo! Sorteos
Consulta si tu número ha sido premiado en
Yahoo! Sorteos http://loteria.yahoo.es