lua-users home
lua-l archive

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


In Bitfighter (a game with Lua scripting), I require users to explicitly declare their vars as either local or global, so there is no ambiguity. Using an undeclared variable produces an error.

This also helps identify spelling errors.

Chris



On 7/1/2010 3:20 PM, Geoff Leyland wrote:
On 2/07/2010, at 9:58 AM, HyperHacker wrote:
On Thu, Jul 1, 2010 at 15:18, liam mail<liam.list@googlemail.com>  wrote:
If I were to be totally honest the thing which I dislike most about Lua is
the keyword 'local'...
I agree, defaulting to global scope is one thing that always irks me
in Lua...

I'm sure it has some advantages, but they're escaping me at the moment.
Local by default used to confuse me no end in Python.  If Lua used it then:

do
   a = 1
   do
     a = 2  -- is this a new local or the same as the one above?  How do I tell Lua whether I want it to be the same or different?
   end
   print(a) -- does this print 1 or 2?
end

I much prefer global by default - it seems do be defined better.

Cheers,
Geoff