lua-users home
lua-l archive

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

On Sun, 7 Feb 2010 13:23:24 +0100
spir <> wrote:

> On Sun, 7 Feb 2010 10:29:23 +0100
> Wim Langers <> wrote:

> > 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?)

In fact, I really need 2 cases, if only to be able to run and test STACK_CATS on its own. So, I found a temporary solution using:
    -- STACK_CATS.lua
    if not pcall(require, "Cat") then require "data.Cat" end
Is this a common idiom?
(Indeed, the 'then' part will save me only if STACK_CATS is itself required from the immediately upper dir ;-) I still think a simple require should work as expected as long as the relative positions of STACK_CATS & Cat do not change.)


la vita e estrany