lua-users home
lua-l archive

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


let me first say that Lua is a great language.  I agree with almost every 
design choice that's gone into it.   The exception is the use of 
'local'.  Perhaps I'm missing something, but I think having a keyword 
called 'global' would have been better.  Writing 'global x' would give 
you access to the global 'x'; writing 'global x=3' would assign/define 
the global.  Otherwise all references would be local.

Currently, 'local' is needed in front of almost every variable in a 
function and I've had several hard to track down bugs from inadvertant 
global access.

It's obviously too late to change Lua, but what about a function 
declaration (called 'method' maybe) that defaults to local and requires 
the use of the 'global' keyword to get outside the scope of the method.

So, you have 

x=0
function test()
x=x+1
end

and

x=0
i=0
method test()
global x=x+1
i='erer' --- global 'i' is unchanged
end

Just some thoughts,
Russ Webb