[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: require cascade
- From: spir <denis.spir@...>
- Date: Sun, 7 Feb 2010 13:23:24 +0100
On Sun, 7 Feb 2010 10:29:23 +0100
Wim Langers <wim.langers@adrias.biz> wrote:
Thank you. Here is a dir tree to sum up the issue:
/app
stack.lua requires "data.STACK_CATS"
/data
STACK_CATS requires "Cat"
Cat
It seems the require cascade does not work because Lua looks for Cat inside /app instead of /app/data.
> you should include the full path to "Cat" as you did with "data.STACK_CATS"
> to the directory from where you started the program.
I think you mean that Cat should be required from STACK_CATS using
require "data.Cat"
Right, this will work because STACK_CATS itself happens to be required from the upper directory. What if this changes, or if STACK_CATS is needed by several modules (eg by a test module in a /test subdir). I mean the relative requiring of Cat by STACK_CATS should be independent on external factors.
Also, I guess this is the same scheme as when a package is required, no? How does the package's main module require utilities? (If the same thing happens, utilities will be searched in package importer's directory. Or is my reasoning wrong?)
> Alternatively you can change your working directory (eg. with lfs) to the
> "Cat" directory (which I don't think is such a very good idea)
Yes, I guess this would ensure the relative requiring of Cat by STACK_CATS. But is this needed, and why then? If it's needed, why do you think it's not a good idea? (What else can I do?)
> the reverse
> may also be true, that you accidentally changed the working directory and
> thus Lua can't find your module anymore.
I do not manipulate the working directory.
> Wim
Actually, I wonder whether Lua apps or packages are simply supposed to hold in a single dir? (Could not find any doc on the topic of structuring them -- PiL itself does not address it.)
Denis
________________________________
la vita e estrany
http://spir.wikidot.com/