lua-users home
lua-l archive

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

On Wed, Nov 2, 2011 at 1:54 PM, Roberto Ierusalimschy
<> wrote:
> Option '-l' would be essentially useless if it did not create the global
> It is intended to be used in interative mode and with the -e option:
>  $ lua5.2 -l mymod -e "print("
> Not polluting the global namespace does not mean a complete prohibition
> of ever creating a global.

-l is intended (and only partly successful) as a shorthand.  However,
I suspect the more important design limitation may be that there is
not a non-debug way to set _ENV from the command-line before entering
interactive mode.  This does not work as intended:

  lua5.2 -e "_ENV=require'myenv'" -i

The lesser concern is what the shorthand for that may be, which
according to the OP's suggestion could be roughly like

  lua5.2 -l_ENV=myenv -i

We may benefit rather from some shorthand for forms like this though:

  lua5.2 -e "_ENV=require'x'(y)" -i

For instance,

  lua5.2 -e "_ENV=require'ziploader'(';')"

which will load the module "ziploader", which then loads the module
"foo/bar/baz.lua" from the file "", loads the module
"qux/bar/corge.lua" from "", stores both of these in some way
of its own choosing in a table with an __index metamethod to _G, and
assigns that to _ENV.  Moreover, other modules require'd by the
interpreter are unaffected by this _ENV.

A possible shorthand is

  lua5.2 -Eziploader=';' -i