[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: require versus straight call..
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Mon, 17 Mar 2008 18:03:00 -0400
> If I use:
> correctly at the top of any packages I might create, does:
> loadfile(modulename ..'.lua')(modulename)
> become equivalent in side-effects to calling:
As you can see in , once found and loaded (the equivalent of
loadfile), if the module has assigned something to
package.loaded[modname] (which 'module' do), 'require' does nothing more
than returning the content of that variable. So the answer is yes.
> In other words, can I simulate a require-style loader directly with
> loadfile, and have the correct side-effects to _G, package.loaded,
> and so forth? And if so, could I do this:
> as well?
Yes again for the same reasons.
An alternative would be to replace:
package.preload[modulename] = loadstring(modulecode)
Just out of curiosity, why do you want to use loadfile/loadstring rather
than require ? require is highly configurable, and if you just want to
alter the way the modules are located and loaded it's very easy to do in