Possible Duplicate:
pass callback from python to c++ using boost::python
I have to make a python function as callback of a c++ function.How to do?Where can I find some examples??
I want to use boost.python.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My approach to this (not the only way)
In C++ I have a class that provides a callback in the following way:
and then when I export the class to python (still C++)
The export of the visitor itself to python
And for the export of
Meshyou doI always used
...where you can insert any of your arguments.In python you do something like this
I also like to make a subclass of
ChildrenVisitorthat accepts lambda functions, that makes writing visitors in python single lines.Oh, btw. if you want to call the function at some later point then you would need to change the C++ implementation to something like this
And make
ChildrenVisitorimplementChildrenVisitorBase.