lua-users home
lua-l archive

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


On 8/07/2010, at 2:44 PM, RJ Russell wrote:

> Here's one way to avoid the issue in code like this and get rid of the globals problem.
> a=1 --auto local
> do
>   a=2
>   --is this a new global?
> end
> print(a) --what is it?
> 
> add one new keyword, global, and keep the local keyword.
> Everything is local by default, not overriding any already existing locals, but the global keyword makes a global, and the local keyword creates a new one.
> 
> a=1 --auto local
> do
>   a=2 --same one
> end

I think I like this.  You might want "function f() ... end" to be by default global or you likely be typing "global function" most of the time.  Any access of (not assignment to) a name that didn't have an in-scope local or global declaration would have to be assumed to be a global, otherwise "print" wouldn't work.

Geoff