lua-users home
lua-l archive

[no subject]

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


An alternative would be to replace:
 loadstring(modulecode)(modulename)
by:
 package.preload[modulename] = loadstring(modulecode)
 require(modulename)
Yep, that's what I want.
Just out of curiosity, why do you want to use loadfile/loadstring
rather than require ?
I wanted to void having to write a loader for require...but as you show above, that 'loader' is as simple as using package.preload[].
Your way is better because it makes it possible to do this:
 package.preload[modulename] = loadstring(modulecode)
 . . . arbitrary amount of time or space in between . . .
 require(modulename)
which also means that the module needn't actually get require()ed unless and until it is wanted. My way effectively forces a require() whether strictly needed or not.
Thanks.

AltStyle によって変換されたページ (->オリジナル) /