lua-users home
lua-l archive

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


On 2015-08-12, at 3:17 AM, mniip <14@mniip.com> wrote:
> 
> On 08/12/2015 06:17 AM, Nan Xiao wrote:
>> 
>> After reading require <http://www.lua.org/manual/5.3/manual.html#pdf-require>
>> section, I am a little confused about the function of package.preload, and it seems
>> that package.loaded is enough.
>> 
>> Why does Lua provide package.preload? Is there any special usage function?
>> 
> 
> You should put built-in modules there. For example if your program has luasocket
> built-in, upon initialization it makes sense to stuff it into package.preload.

Yes. 

package.loaded is for modules which have been initialized.

package.preload is for modules which have not yet been initialized. These modules are like dynamically-loaded plugins which have not yet been loaded.

Jay