[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: tables problem
- From: "Wim Couwenberg" <wcou@...>
- Date: Tue, 27 Jan 2004 09:48:12 +0100
> but do you actually need the local statement in Lua 5?
> In Lua 4, sure. But I thought that we were "lexically scoped" now.
> Doesn't that mean that a is automatically local to the function?
No. Name lookup is still te same as in Lua 4: a variable name is searched
outward (in nested scopes) and upward (in script.) If it is not found in a
local statement or as a function argument (including implicit `self' and
`arg') then it is assumed to be a global, i.e. it will be looked up in the
function's environment.
What lexical scoping added compared to Lua 4 is:
- upvalues do no longer need to be declared in the inner most enclosing
scope,
- upvalues are mutable,
- no `%' syntax anymore (yay!),
- no global upvalues anymore (declare them local first).
So the `a' in the example would still be global if not explicitly declared
local.
--
Wim