lua-users home
lua-l archive

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

On 27 February 2011 20:40, Sebastien Lai <> wrote:
> Recently I've stumbled upon an annoying, if not strange behaviour regarding
> the behaviour of 'require()'.
> In short, it seems that require() only searches from the directory from the
> script that is being called

Exactly. It works like PATH, LIBRARY_PATH, LD_LIBRARY_PATH &c. (Using
relative paths for require is, therefore, not recommended.)

> That is, Lua does not search the relative path, which makes using organized
> module directories rather tiresome to use...

If you mean that it doesn't encourage hierarchical module directories,
then, no, it doesn't. Something "required" is at the level of a
library, not of a module.

If you want to think of your requires as modules, you can use the same
solution as Perl, which is to

require "lib/submodule"

which makes your intent much more obvious than using relative paths.

(Which languages do use relative paths for this? Java doesn't, Perl
doesn't, C doesn't, Python doesn't...)