[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: 'name conflict for module' with Compat-5.1
- From: "Jarno van Rooyen" <jarno.vanrooyen@...>
- Date: Mon, 30 May 2005 11:51:15 +0200
> > I create a global value called Component1 (it can be anything but a
> > e.g. Component1 = function() end
> > Then I try to require 'Tests'. I end up with
> > compat-5.1.lua:122: name conflict for module `Tests.Component1'
> Can you list the exactly contents of your Feature1.lua file? I'm not sure
> I'm fully understanding your problem, but it may be just a question of
> line reordering. See below.
The entire contents of the Feature1.lua is
The problem I'm experiencing is that it is possible to either prevent a
library from loading or loading it into unexpected tables by declaring global
variables. See below.
> > I have not tested this with work6. Is this the intended behaviour? This
> > implies that one can have a namespace A.B, but not have the B table an
> element of A.
> > B can be a "global".
> That's the part that lost me. Since you have "Component1" both as a Lua
> file (part of the Test package) and a directory (where Feature1.lua is
> located) I'm not sure what module hierachy you want.
> Do you want to have both the A.B.C namespace and a global (declared in
> A/B.lua) called C? If that is the case then you can try defining C before
> the definition of namespace A.B.C, as in (not tested)
> C = function() end -- this is C, global
> module "A.B.C" -- from this line forward every "global" ends in the A.B.C
> function D() -- this is A.B.C.D
> C() -- calls the global defined before the module definition
> Would that work for you? Maybe I'm completely off mark here...
This would work, but I do not have control over C = function()... . C is not
a function that the package needs. It is just a "global" function that the
user created before requiring the package. The presence of the function
causes the name conflict.
I'll try to explain my setup:
I want tables (containing namespaces) as follows:
Tests.Component1 -- Contains all the tests for Component1
These namespaces are created by 3 files:
./Tests.lua - Loads all the components
./Tests/Component1.lua - Loads all the features of component 1
./Tests/Component1/Feature1.lua - Loads the tests for Feature1
The location of the files is necessitated by the conversion of package name
to file name in the require statements. The contents of the Tests.lua and
Component1.lua files are just require statements to load the sub packages,
./Tests/Component1/Feature1.lua must make its contents available in the
Component1 namespace, thus:
... some more code to implement tests for feature 1.
When there exists a global variable with the name "Component1", the loading
of the tests will fail if the variable does not reference a table. I don't
know beforehand which global variables will exist. I can probably restructure
this to make it work, but that will not make the issue go away.
To summarise: It is possible to either prevent a library from loading or
loading it into unexpected tables by declaring global variables with this
implementation of compat.
Is this the intended behaviour?