From: Boris M. <bor...@la...> - 2006-09-06 16:26:34
|
Hi, I am trying to do some kind of plugin system in TCL, with SWIG, from C++ objects. I am new to SWIG so I am wondering if I use import/include directives correctly. Suppose I have a main module in which I have a base class A (with virtual methodes and non-virtual methodes) and a function that takes a A pointer. For example, A.hpp is : -------------------------------- class A { public: A(); virtual void f1(); void f2(); }; extern void f(A *a); // f will call a->f1() & a->f2() -------------------------------- and A.i is -------------------------------- %module AM %{ #include "A.hpp" %} %include "A.hpp" -------------------------------- From these files (and A.cpp not shown here) I get a AM.so I also have a class B redefining the virtual methods (B kind of classes will be my plugins). For example : -------------------------------- class B { B(); virtual void f1(); } -------------------------------- From which I get a BM.so and I want to use these two modules in a script. For exemple, test.tcl is -------------------------------- #!/usr/bin/tclsh #load modules load AM.so load BM.so #define a B object B my_b #call f() with B object as parameter f my_b -------------------------------- How do I write B.i to have the correct behavior ? If I write B.i -------------------------------- %module BW %{ #include "B.hpp" %} %import "A.hpp" // "import" here !!! %include "B.hpp" -------------------------------- when I call "f my_b" in the script, it is known that B inherits from A (so f1() from B is called), but f2 is not wrapped for B ! If I write B.i as -------------------------------- %module BW %{ #include "B.hpp" %} %include "A.hpp" // "include" here !!! %include "B.hpp" -------------------------------- it works correctly but the A's wrapping is both in AM.so & BM.so, isn't it ? So A's wrapping will be in each of my plugins ! Is it the right way to achieve what I want ? Thank you, Boris. |