lua-users home
lua-l archive

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


You're right.  I will just have to make a table and pass it in.

thanks,
wes

On 5/31/07, Will Leshner <will.leshner@gmail.com> wrote:
On 5/31/07, Wesley Smith <wesley.hoke@gmail.com> 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:

<http://en.wikipedia.org/wiki/Scope_(programming)>