lua-users home
lua-l archive

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


Lua loop counters are in their own local scope. I've known for some time,
but now I really just want to know why. I am evaluating other languages
and would like to know... Would this be done the same way if you had a
chance to rewrite Lua without backwards compatibility. If so, why?
If not, how hard would this be to change in my own no-longer-Lua branch?

  i=999
  for i = 1, 10 do
    print(i)
  end
  print(i) -- prints 999

  -- What other places does this sort of thing occur?

Second, aside from some weird scoping stuff (the above as well as global
default vs local), one thing I miss in Lua are named parameters such that
the following would be valid code (and very useful imho).

  function f(a=1,b=2,c=3)
    ...
  end

  f(c=999,a=0)

Is this possible somehow, or could I work to add it fairly easily?

Finally, I can't remember specifically but wasn't there some unpopular
global vs local default scope issue that was going to be changed?
I think it was simply that local would be implicit instead of global.

Just looking at Python, Ruby... I still love Lua, it's faster and easier.
Thanks!