lua-users home
lua-l archive

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


2011/10/10 Sebastien Lai <237482@googlemail.com>:

>
> Unfortunately, when I've learned Lua i managed to overwrite 'arg'
> unknowingly, by doing something pretty harmless:
>
>     for arg in pairs(args) do
>        ....
>
That "arg" is local to the loop.  Inside the loop, you need to refer
to the global arg as
_ENV.arg.  So while I believe you that you managed to overwrite 'arg'
unknowingly,
it did not happen this way.

> argv:
>   in C/C++/C#/Java/Erlang, the 'commandline argument vector' is
> usually passed to the main function.
>
So too in Lua 5.2.  Just remember: your'e already in the main function at line 1
(or line 2 if you're using the "#!" feature).

>   in Perl,
>   in Ruby,
>   in python,
> All these languages encapsulate such data in a way that reduces 'accidental'
> overwriting of the argument vector variable, or version information.
>
Well, if you want to use one of those, you know where to find it.

IMHO the only way that you can 'accidentally' overwrite the argument
vector variable
or version information is by reprehensible coding habits.  It can't
happen if you:
  - process arg and give useful names to what's in it before anything
else gets loaded;
  - refrain from defining your variable names to start with underscores.

Dirk