lua-users home
lua-l archive

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


>From the package.searchers documentation:

"The third searcher looks for a loader as a C library, using the path given by the variable package.cpath. Again, the search is done as described in function package.searchpath. For instance, if the C path is the string

"./?.so;./?.dll;/usr/local/?/init.so"

the searcher for module foo will try to open the files ./foo.so, ./foo.dll, and /usr/local /foo/init.so, in that order."

Robert

----- Original Message -----
> From: "Robert Virding" <robert.virding@erlang-solutions.com>
> To: "Lua mailing list" <lua-l@lists.lua.org>
> Sent: Friday, 6 December, 2013 3:52:52 PM
> Subject: Re: Search paths in require/packages
> 
> That sounds definitely weird. How do I then tell require *where* to look for
> the module? So if I write "a = require 'foo'" how does does the loading
> mechanism know where to look for 'foo'? The default path values imply that
> requiring a 'foo' will try to find either a foo.lua or an foo/init.lua in a
> number of different places. This is also described in the package.searchers
> description, both by referencing package.searchpath() for Lua loader and
> very explicitly for the C library loader.
> 
> So if the paths are for finding loaders how do I tell where to find the
> modules? Does that mean I have to give the absolute path for require?
> 
> Robert
> 
> ----- Original Message -----
> > From: "Jerome Vuarand" <jerome.vuarand@gmail.com>
> > 
> > 2013/12/6 Robert Virding <robert.virding@erlang-solutions.com>:
> > > Yes, it is clearer. The current sentence implies that used to FIND a
> > > loader
> > > and not that it is used BY a loader. Require doesn't directly know about
> > > files although it does know about an extra argument apart from the module
> > > name which is passed in the call to the loader.
> > 
> > I think you're confusing some concepts here. The path is not used "BY
> > a loader". The path is used "BY a searcher to FIND a loader". The
> > loader is not aware of the path.
> > 
> > The loader is not the code finding or compiling the module, the loader
> > is the module init function (luaopen_ in C or the module script body
> > in Lua). The function finding loaders, compiling them (if necessary)
> > and returning them to require is called a searcher.
> > 
> > 
> 
>