[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Private modules, was Calling module from a C function
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Fri, 27 Apr 2007 10:48:11 -0400
Tomas Guisasola wrote:
>> There's another issue with multiple parameters to require. Require
>> parameter got passed not only to the module itself, but also to the
>> module loader which loads the module. It would be nice to pass
>> optionnal parameters to the module loader. For example imagine you
>> have a loader that will retrieve modules from an online module
>> repository (through http), it would be nice to pass the url of the
>> server as the require second argument. From my point of view that
>> would be much more useful to parameterize the loaders than the
>> module themselves.
> Maybe I am not following your thoughts but I think that this
> loader might be configured to work properly in a particular
> environment and this should not be the case of the programmer that is
> trying to load a module. Don't you agree?
An example may be clearer. Suppose that you have a loader that get Lua
rocks from the net:
-- Install the loader
-- Get some modules from the official rocks website (fictionnal url)
-- Get some modules from your corporate intranet quality assurance site
And from here you can use modules lxp, pdf, and syslog as normal
modules. There are other solutions to the problem, I could for example
embed the url in the module name like require("org.lua.rocks.lxp"), or
as methods of the loader module, but that can be done to modify normal
modules too. My point is that extra parameters to require may be used to
configure how module are loaded rather than how modules will work.
>> On the other hand, for a given application, you can easily and safely
>> modify require, module and the loaders to manage these extra
>> But you won't be able to use third-party modules.
> In this case it is not a simple task, because you will have to
> rewrite `require' -- which is not a simple function -- to change only
> the call of the module function!
'require' is not that complicated. It's clearly organized around a
loader concept, and it's very generic and flexible. The apparent
complexity shown in its manual entry comes from the fact that there are
4 different loaders for only 2 module types in stock Lua, but each
loader independently is also very simple. They are ordered in such a
clever way as to handle several special cases.