lua-users home
lua-l archive

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


2011/11/3 Matthew Wild <mwild1@gmail.com>:
>
> I'm confused... if you're going to use require(), that also sets
> package.loaded if not already set. So... how is -l useful if you have
> to call require right after anyway?
>

Don't think of '-l' as being merely convenient.  Think of it as
providing command-line control over loading of modules.

For example: the program has:

mod1 = require "mod1"
mod2 = require "mod2"
mod3 = require "mod3"
…
mod12 = require "mod12"

These modules are supposed to be independent of each other, but the
program has an obscure bug.  You suspect that one of these modules is
setting a global which affects one of the others.  Without any need to
edit the source (which may have been supplied to you as bytecode) you
can do this:

   $ lua -l mod4 prog.lua

Now "mod4" gets loaded first.

And this sort of application is why I'm pushing for extending the
syntax of '-l' to allow

  $ lua -l mod4=mod4_patched prog.lua

That would allow '-l' to achieve command-line templating.

Dirk