|
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 www.lua.org/pil/4.2.html about blocks and scope, maybe you'll get a better understanding.
On Tue, Oct 11, 2011 at 7:22 AM, Dirk Laurie <dirk.laurie@gmail.com> 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)
end
-- 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