[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What does lua_upvaluejoin do?
- From: Peter Cawley <lua@...>
- Date: Sun, 3 Apr 2011 22:18:46 +0100
On Sun, Apr 3, 2011 at 10:12 PM, Jan Behrens <public@magnetkern.de> wrote:
> On Sunday 03 April 2011 22:53:57 Peter Cawley wrote:
>> Your program creates C closures, not Lua closures. The documentation
>> explicitly mentions that it only works on Lua closures.
>
> For which reason does the API need a function to
> join upvalues of Lua closures only? Can someone
> name a usage case?
The existing behaviour of the VM is that upvalues of a C closure are
never shared with any other closure, whereas upvalues of Lua closures
can be shared between multiple Lua closures. The current behaviour is
also that Lua closures can only share upvalues if the two closures
were defined in the same lua_load call. This function allows that to
change. There are two uses which come to mind immediately:
1) Allowing Lua closures to be (de)serialised whilst still maintaining
upvalue relationships.
2) Allowing an REPL interpreter to make locals defined in earlier
lines available to later lines.