lua-users home
lua-l archive

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


Peter Hill:
> The question, though, is which *object* the lexically scoped variable 'a'
> (not its content object) is living in.
[..snip snip..]
> I don't know how the new lexical scope is implemented... which is why I'm
> hoping someone who knows the new internals might tell me what's going on.

Upvalues are kept in a structure that is not public to
either the Lua or the C interface.  Each upvalue gets its
own structure, which is then shared between all closures
that refer to this upvalue.  Think of an upvalue as a reference
to a Lua object (i.e. an extra level of indirection.)  As
long as the actual object still resides on the stack (as a
local), the upvalue refers to that stack slot.  Just before
the local goes out of scope, its value is copied over into the
upvalue structure (the upvalue is "closed".)  Exactly where
an upvalue object resides is opaque to closures.

> If it *does* prevent GCing of inaccessible objects then that needs to be
> mentioned in the manual.

Closures never "lock" more objects then strictly necessary
so gc will perform as expected.

Bye,
Wim