[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Relative imports
- From: Henk Boom <henk@...>
- Date: Wed, 9 Mar 2011 02:54:08 -0500
On 28 February 2011 17:49, Reuben Thomas <rrt@sc3d.org> wrote:
> On 27 February 2011 20:40, Sebastien Lai <237482@googlemail.com> 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...)
Actually, C does. Some projects do something like -I. and use absolute
paths anyway though.
henk