[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: closure upvalues
- From: Ignacio Castaño <castanyo@...>
- Date: Fri, 24 May 2002 22:22:19 +0200
Ignacio Castaño wrote:
> Roberto Ierusalimschy wrote:
> > > Is it possible to get the closure upvalues without calling it?
> >
> > No (maybe we will add this facility to the API).
>
> It would be really usefull, specially now, that it's quite elegant to bind
a
> metatable to a class constructor to create objects of that class. I don't
> know much about lua internals, but I'll try to do it myself...
well, I've done it. I will test it now, but I'll throw it here in case
someone sees something wrong...
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
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com