lua-users home
lua-l archive

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

An alternative would be to replace:



 package.preload[modulename] = loadstring(modulecode)

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 . . .

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.