lua-users home
lua-l archive

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


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, for example:


/path/to/somedir/main.lua
|-->�/path/to/somedir/system/
|---->�/path/to/somedir/lib/foo.lua
|---->�/path/to/somedir/lib/stuff.so

Main.lua being:
�� �package.path = package.path .. ";../system/lib/?.lua"
�� �require("foo")

Foo.lua being:
�� �require("stuff")

In this case, the VM will search for "/path/to/somedir/stuff.lua", or "/path/to/somedir/stuff.so", but not for "/path/to/somedir/system/lib/stuff.so" or "/path/to/somedir/system/lib/stuff.lua", as for example Python does.

That is, Lua does not search the relative path, which makes using organized module directories rather tiresome to use...
It wouldn't be all that terrible if one wouldn't have to explicitly add the following to "main.lua":

�� � package.cpath = package.cpath .. ";../system/lib/?.so"

A wake mind will see the problem here: the line has to be modified to match the extension for shared libraries on each system.
I simply do not believe that this is intended, and writing a crossplatform version of 'dirname' is trivial, so why is this functionality not part of Lua yet?