On 03/02/2010 09:18 PM, puneet goel wrote:
Mathew/Jim

If you just need your Python interface to support calling those function
pointers, not adding new functions in Python, it's relatively easy.
Thanks for your support.

Actually I need to pass data from Python to C++.  I am required to
pass Python functions as part of the structure in a way that these get
executed somewhere in C++.

Now that I know that this can not be done in a straightforward manner,
  I am looking for a workaround.

I'm not sure what you mean by "straightforward" and "workaround". Python functions are objects, as anything else in Python. And to call them, you invoke the operator() on them.

Since Python functions are objects, you can pass them around and store them in what I would call a very straightforward way. There is really nothing special about them.

  I would like to know whether it is at
all possible to pass a Python function, as data, to C++ using
boost-python. What would be the C++ type of a structure element that
would be able to hold a Python function when passed using
boost-python?

To clarify, if I get the C++ API changed to something like

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

  foobar func1;
  foobar func2;
};

What type (in C++) would foobar be so that I am able to pass a python
function for func1 and func2?

boost::python::object.


    Stefan


--

      ...ich hab' noch einen Koffer in Berlin...

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

Reply via email to