[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Command line library load in Lua 5.2
- From: David Manura <dm.lua@...>
- Date: Wed, 2 Nov 2011 23:19:10 -0400
On Wed, Nov 2, 2011 at 1:54 PM, Roberto Ierusalimschy
> 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(mymod.foo(10))"
> 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
lua5.2 -e "_ENV=require'ziploader'('foo.zip:foo.bar.baz;qux.zip:qux.bar.corge')"
which will load the module "ziploader", which then loads the module
"foo/bar/baz.lua" from the file "foo.zip", loads the module
"qux/bar/corge.lua" from "qux.zip", 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='foo.zip:foo.bar.baz;qux.zip:qux.bar.corge' -i