Re: Modifying a Closure in 5.0 Alpha
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Modifying a Closure in 5.0 Alpha
 
- From: Edgar Toernig <froese@...>
 
- Date: 2002年8月23日 00:29:10 +0200
 
Peter Loveday wrote:
> > > So I either need a means to add an extra value to the existing
> > > closure, or query the previously pushed function and values,
> > > then re-push it all with an extra one.
> >
> > Use lua_pushupvalues to get all upvalues in the stack and lua_tocfunction
> > to get the C function back and then create a new closure as needed.
> 
> I can't seem to get this to work. lua_pushupvalues() seems to return 0,
> when called with the function I'm interested in on the top of the stack.
lua_pushupvalues pushes the upvalues of the currently active C function.
And in that case it would be much easier to use
 lua_push<something>
 lua_replace(L, lua_upvalueindex(x));
You cannot _add_ new upvalues with lua_replace but you can change them
(add some nil-upvalues initially...).
The other way would be to not change the upvalues but change the contents
of a table that the function has as an upvalue. Then you can do whatever
you want...
Ciao, ET.