[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] mergelua
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Mon, 17 Oct 2011 10:31:59 +0200
2011/10/16 Sebastien Lai <237482@googlemail.com>:
> On Sun, Oct 16, 2011 at 3:40 AM, David Manura <dm.lua@math2.org> wrote:
>> I believe it's preferred to utilize package.preload rather than
>> override require.
>
> I've been trying to insert package.preloade[<modulename>] = <etc> in
> different ways, but it did not quite work for me.
Here is a simple working example :
package.preload.a = function(name)
return {
_NAME = name,
f = print,
}
end
local b = require 'a'
assert(b.f==print)
assert(b._NAME=='a')
assert(_G.a==nil)
What may not be clear is that preload must not contain the modules
themselves, but rather loader functions (that is, the functions that
will actually create the module, for example the body of a module
file).