lua-users home
lua-l archive

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

On Fri, Nov 4, 2011 at 10:10 PM, HyperHacker <> wrote:
> I feel like this idea has been brought up before, but I don't recall
> the consensus. Presently, require() accepts only one argument. Why not
> change it to require(name, ...) and pass all additional args on to the
> module? The module can then retrieve them from ... just as it would if
> you did loadfile(name)(...).

Now sure about consensus, but in `loadfile(name)(...)` you are passing
the arguments to the loader.  Once require loads a module it caches
it.  So, if another call is later made to require for the same module
but with different arguments, the new arguments are ignored because
the loader is not re-invoked again.  You therefore have in a way a
race condition where the behavior depends on the order in which
modules are loaded.

Sometimes I do things like `local X = require 'foo' (...)`, which
achieves the desired effect.  IMHO, the 'strict' module in Lua 5.1
should have operated this way, with the environment to strict-icize
passed as the argument.