lua-users home
lua-l archive

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


> > Is it so that upvalues only "care" about functions?
>
> Yes.
>
>
> > But if that block is changed into a function, an error message occurs...
> >
> >  "upvalue must be global or local to immediately outer scope"
>
> The message should be "... to immediately outer function".

Ah. I see. Actually, this works like normal variable lookup
at the point of the function definition, right? (I.e.
shadowing is in effect.)

This leaves me with just a couple of other questions: Firstly,
why can variables be local to the main chunk? As far as I can
see, there is no way to access them?

And secondly, why can inner functions refer to global variables
only when they aren't shadowed by a variable local to a
surrounding scope? Is this an implementation issue, or is it
simply assumed that users want to use the local ones, and
they can't without upvalues?

Both these issues seem a bit arbitrary to me, but I am sure
I'm missing something important :)

--

  Magnus Lie Hetland      (magnus at hetland dot org)

 "Reality is what refuses to disappear when you stop
  believing in it"                 -- Philip K. Dick