Calling Python functions from C++ -
i trying achieve call python functions c++. thought achieved through function pointers, not seem possible. have been using boost.python
accomplish this.
say there function defined in python:
def callback(arg1, arg2): #do return
now need pass function c++, can called there. how write code on c++ side using boost.python
achieve this?
if might have name:
pass function takes boost::python::object
.
bp::object pycb; //global variable. store in map, etc void register_callback(bp::object cb) { pycb = cb; }
if in single known namespace consistent name:
bp::object pycb = bp::scope("namespace").attr("callback");
bp::object
has operator()
defined, call function
ret = pycb()
Comments
Post a Comment