[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Relative imports
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Mon, 28 Feb 2011 11:09:14 +0100
2011/2/27 Sebastien Lai <firstname.lastname@example.org>:
> 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:
> 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?
Because all those trivial functionalities people are asking for would
add up and you would end with a big bloated interpreter. In the
tradeoff between compactness and full-featuredness, Lua is leaning
toward the former, in terms of source code size, compiled size,
external dependencies, memory footprint.
Maybe you should have a look at bigger Lua distributions (LuaDist,
LuaRocks, Lua for Windows, etc.), they may already have solved your