lua-users home
lua-l archive

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

On 5/31/07, Wesley Smith <> wrote:

What I'd like is f1's val upvalue to refer to constructor's local
variable val.  Is this possible somehow through environments?

It looks like you are expecting dynamic scoping, but I believe Lua
uses static scoping (which is actually a really good thing as upvalues
and closures wouldn't work at all with dynamic scoping).

Wikipedia appears to have a pretty good page describing the difference
between dynamic and static scope, and there's even an example they use
to compare the two that looks a lot like your example. The page in
question is here: