lua-users home
lua-l archive

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

Hello, again.  Did anyone get my last message about locals?  Sorry to 
repost if it was just too uninteresting to respond to.

I'm wondering why Lua defaults to global for variable access in 
functions.  Most of the time local default is what I need and polluting 
the global space unintentionally can lead to some difficult bugs.  I know 
one can just stick a 'local' in front of everything, but one can also 
program without functons using a goto.

I have two suggestions:
1.  could some form of fallback govern local vs. global defaults?  this 
probably isn't the best way.
2.  how about a new function declaration keyword, say 'method', which 
defaults to local access and a new keyword 'global' that gives you access 
to globals from within functions:
	method test()
		print(x)        -- error
		x='a string'    -- global x=10 still
		print(x)        -- prints 'a string'
                print(global x) -- prints 10