lua-users home
lua-l archive

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

The concept that confuses you is called a "scope". The "overwriting" happens to all variables, not only arg. Actually, no overwriting happens at all - you are just referencing other local with the same name that shadows the original variable. As you noticed, everything is ok after the block ends.

Please read about blocks and scope, maybe you'll get a better understanding.

Dňa 11.10.2011 9:42, "Sebastien Lai" <> napísal(-a):
On Tue, Oct 11, 2011 at 7:22 AM, Dirk Laurie <> wrote:
> I'm trying to guess what you mean by "overwritten inside the loop".

I don't know why you have to "guess" something as obvious as this, but
have at it.

stuff = {"red", "green", "blue"}
for _, arg in pairs(stuff) do
   -- arg is no longer the "commandline argument vector" here.
   -- anyone who has mastered the Lua tutorial should know that.
   print("stuff:", arg)

-- but since 'arg' is local to the for loop, it is only overwritten
__inside__ the for loop.
for _, s in pairs(arg) do print("arg:", s) end