lua-users home
lua-l archive

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


On Tue, Nov 23, 2010 at 1:21 PM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> > Try require"xxx". Then Lua will search package.path for xxx.lua.
>
> Can require (or a derivative therof) be made to search a custom path?  I
> think that this is what Dirk was asking, and I'd like it as well.

Isn't package.path a custom path?

Yes, it is, but it is used by require.

Editing package.path to include directories in my project would mean that I would have to verify that every file in my project didn't match anything in package.path. 

The reverse also applies -  I'd have to check that a module I download doesn't share a name with a file in any of my existing projects, and edit those projects before adding it to my installation. The contents reached by package.path are likely to change over time as I add things to my installation, which could cause something to break in an existing project without making any changes to the source of that project. Yuck.

Lua 5.2's package.searchpath (pointed out by Roberto) allows the use of an arbitrary number of independent paths, so require(name) can use one path and dofile(package.searchpath (name, path)), or something more complex if necessary, can use other paths.