Extending a C++ App
Mark Rowe
bdash at gmx.net
Fri Sep 13 06:13:10 EDT 2002
Hello,
>I looked at SWIG
>However I have a few concerns (forgive me if Im being dense)
>
>(1) All the examples are created as DLLs (ie APIs)
> This is fine - except how would my C++ App use the same object instances?
> (ie. share the memory and API objects)
>
Last time I looked I couldn't find much information on this topic,
but after stumbling around in the dark for a while I found the
function SWIG_NewPointerObj, which takes a pointer and creates a
PyObject * of the specified type from it. This can then be inserted
into a Python namespace using the Python C API.
>(2) SWIG does not do a nice job of object wrapping (in my opinion)
> For instance instead of saying
> c = example.Circle
> c.x = 10
> c.y = 20
> del c
>
> I need to do this:
> c = example.new_Circle()
> example.Shape_x_set(c,10)
> example.Shape_y_set(c,20)
> delete_Circle(c)
>
> Isn't there a cleaner library somewhere to do this?
To get around this, tell SWIG to generate shadow classes for the
objects. eg, use the command `swig -python -c++ -shadow circle.i'.
This will generate a Python source file with classes that wrap the
methods you mentioned above (example.new_Circle, etc).
Mark Rowe
More information about the Python-list
mailing list