Embedding/Extending Python in/with C++: non-static members?

Nick Craig-Wood nick at craig-wood.com
Wed Jul 18 00:30:03 CEST 2007

dmoore <damienlmoore at gmail.com> wrote:
>  I've obviously spent too much time with dynamic languages. The problem
>  with what I'm trying to do is obvious: In C++ you simply can't pass
>  pointers to call a particular instance of a C++ class method so there
>  is no way to initialize the PyMethodDef with class methods instances.

It is possible in theory.  You can do what python does when it makes a
bound method and build a custom function at run time with the instance
and method built in.

How you build that function is tricky - you've basically got to poke
object code onto the heap which implements the method call to that
particular instance.

Looking at this page might give you some ideas


This probably isn't a good approach in reality though as it is very
architecture / compiler dependent!

Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick

More information about the Python-list mailing list