[C++-sig] Boost Python: C++ struct with a function pointer

Matthew Scouten (TT) Matthew.Scouten at tradingtechnologies.com
Tue Mar 2 19:14:38 CET 2010


Not in any straight forward way. C++ function pointers need to exist at
compile time, while python functions do not exist till runtime. 

You might have a few work abounds, depending on use.

The most obvious is to hardwire the pointers to known c++ functions that
call python functions after some kind of table look up. 

Another is to create some delegate objects in c++ that have a fnptr data
members not exposed to python. Your foo object will then wrap the data
members as propertys that take a delegate and extract the fn pointers
and visa-versa 

Implementation is left as an exercise to the student.

-----Original Message-----
From:
cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org
[mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py
thon.org] On Behalf Of puneet goel
Sent: Tuesday, March 02, 2010 5:10 AM
To: cplusplus-sig at python.org
Subject: [C++-sig] Boost Python: C++ struct with a function pointer

Greetings

I am boost.python newbie. I tried searching the web for a solution but
could not find one.
I am trying to generate Python Bindings for a C++ API. The API has
some data structures with a set function pointers as its members.

struct foo {
public:
  int a, b;
  char *str;

  int (*func1) ();
  int (*func2) ();
};

I am wondering if it is possible to bind this struct to Python. Let me
know how this can be done.

Regards
- Puneet
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


More information about the Cplusplus-sig mailing list