lua-users home
lua-l archive

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

On Wed, May 4, 2011 at 3:00 PM, Lorenzo Donati
<> wrote:
> The lines that I don't understand are those where debug.upvaluejoin is
> called. Why is this call needed? Isn't debug.setupvalue enough?

In 5.1, each closure had an individual environment, and changing the
environment of one closure would not change the environment of any
other closures. On the other hand, upvalues can be shared between
multiple closures, so that changing the value in one closure affects
what other closures subsequently see. Hence to replicate the 5.1
behaviour, you need to ensure that the upvalue that you're setting
isn't shared with any other closures, so the conceptual behaviour is:
debug.splitupvalue(f, up) -- this function doesn't actually exist
debug.setupvalue(f, up, t)
Splitting can be implemented in terms of joining against the upvalues
of a temporary closure, and then setting can be combined with
splitting into a single call to debug.upvaluejoin.