lua-users home
lua-l archive

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

> function dofile(filename, ...)
>   local env = setmetatable({ arg = {
>         [-1] = arg and arg[-1], -- Lua executable
>         [0] = filename, -- Lua script
>         ... -- Script arguments
>      }},
>      { __index = _G, __newindex = _G })
>   return setfenv(assert(loadfile(filename)), env)(...)
> end

Thank you for these corrections of this dofile() function.

But my actual point was to discuss the possibility to introduce or not
additional arguments to dofile in a future release of Lua (maybe 5.2
That feature is quite handy and is backward compatible.
There are some drawbacks of course: a little additional C code, and
the behavior of  'arg' table which is not easy to define.
By the way, I noticed that dofile in Lua [1] does not touch the global
'arg' table at all, which could lead to some bugs.
The script called by dofile sees the same 'arg' table than the caller
script, although arguments retrieved though the '...' mechanism are
different: this seems strange.
A side question: do we really still need that global 'arg' variable? I
personally never use it.

Patrick Rapin