lua-users home
lua-l archive

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

On Mon, Mar 31, 2008 at 10:52 AM, ketmar <> wrote:
>  > Do both functions share 'a' as an upvalue?
>  yes.
>  > If so, how can they hold a reference to a simple
>  > value (as opposed, for example, as to a table)?
>  compiler magic, upvalue is a special reference that is invisible to
>  user (but you can examine it with debug library).

i think 'upvalue' is a misleading term.  it's just a local variable,
local to the do...end block and not to either of the functions.  (of
course that block exists inside the chunk's function).

AFAIUI, the execution of the do...end block creates the storage for
the variables (how would that be called? i guess it's not a 'stack
frame'), and the functions (closures, in fact) reference that local
vars frame.