I have the following code, which implements a simple C++ class (ObjWithPyCallback) with a Python callback function. The idea is to call the Python function with \"this\" as the
I would use SWIG's mechanisms for handling inheritance and have a callback class with a virtual function void call()
. Then you use SWIG to enable that class to be derived from in Python.
In Python, you simply make sure that where the callback is set, you wrap it in an instance of a Python class derived from the C++ callback class, and make it's call
member function execute the callback. That's also where you'd do the test to see if it's callable. Then you would call the setCallback
function with this wrapper object.