create a c++ wrapper for python class?

Diez B. Roggisch deets at nospam.web.de
Wed May 10 19:57:06 EDT 2006


Mark Harrison schrieb:
> Right now I'm using Boost Python to wrap some C++ code so
> that applications from both languages can use it.
> 
> This is great, but I'm rapidly coming to the conclusion that
> a lot of this work is better coded in Python.  There's nothing
> particularly CPU-bound, and the comprehensive Python library is a 
> big help.
> 
> So, I'm looking for a C++ wrapper generator, so that I can
> write a class in Python, and then have a .h and .cpp generated
> that will give me a corresponding C++ class.
> 
> Of course, the usual restrictions apply:  no dynamically
> added methods, accessing all instance data via getters
> and setters, etc.
> 
> It seems a first cut of  this is pretty straightforward,
> using introspection to get the required methods.  Something
> needs to be done to specify the C++ types of the parameters.
> 
> Is there any work being done in this area?

No - and I doubt there is much to do about that. C++ needs so many 
static information to form a proper class, you'd end up duplicating the 
whole declarational efforts in some awkward addition or complementary 
annotation to python's syntax that it just isn't feasible. There is 
shedskin, avery interesting project, but then this sufers from being a 
subset of python and AFAIK no  seamless interoperability between python 
and C++.

I don't know  about boost - but I know my way around SIP a little bit. 
So what I would do is to declare whatever you need in C++ in a class 
with all virtual methods. SIP then should be able to let you subclass 
that class in python, and pass back instances of your python classes to 
your C++-core/library/whatever.

Diez



More information about the Python-list mailing list