|
From: William S F. <ws...@fu...> - 2010-03-18 21:39:07
|
Sebastian Wolff wrote:
> Hello everybody,
>
> I think I have found a serious bug in the Lua bindings of SWIG and hope
> you someone else also encountered this problems and found a solution
> for this.
>
> Suggest you have two SWIG modules, "A" and "B". Also suggest you use
> different namespaces in both modules with equally named classes, say:
>
> library A:
>
> namespace A
> {
> class classname
> {
> //! constructor
> classname(const std::string & ident);
> ...
> };
> }
>
> and library B:
>
> namespace B
> {
> class classname
> {
> //! constructor
> classname(const int & id);
> ...
> };
> }
>
> Then both libraries will be wrapped by SWIG into 2 different modules
> and linked together. In Lua, you expect to be able to call:
>
> a = A.classname("hello") -- call constructor of A::classname
> b = B.classname( 3 ) -- call constructor of B::classname
>
> SWIG actually merges equally class names from different namespaces into
> one. That is, if the load_module routine of module A was called before
> B, then it expects the syntax of A::classname, if B.classname( ... ) is
> called.
>
> I am using latest SWIG 1.3.40
>
> Any help or suggestions?
>
> I asked here, because the bug tracker on sourceforge is quite inactive
> regarding Lua...
There isn't anyone around at the moment who is working on Lua, so until
someone volunteers not much is likely to happen for Lua.
However, I took a look at this and this is a general problem that is not
Lua specific. I'm assuming your 2nd module will %import a file
containing A::classname, and %include a file containing B::classname.
The problem is SWIG flattens the namespaces and so it is not possible to
wrap classes of the same name unless you rename one of them. If you
%include both of these class definitions you will get a warning telling
you that one has been ignored. However, there is no warning generated
with a %import and a %include when the symbol names would clash in the
target language. That is arguably a bug. Also there are some strange
side effects when using %include and %import of an identical type, which
should give an error or warning. Something else to do.
William
|