Major upvote to this! I’m looking for both 1 and 2. I’ve used boost python and pybind11 moderately recently and pybind11 is waaaay better.
// inside CPlusPlusExample::execute(…) {
PyObject *p = something;
p = py::make_tuple("collisionStart", 42.);
// if a certain condition is met then
plugin_callback(p); // all custom plugins would have plugin_callback, which can't be modified
Inside a ParExecuteDAT or something new maybe
# this becomes a default function that the user can customize
# a lot like def onPulse(par):
def plugin_callback(obj):
# do something with obj.
# obj could be whatever the user determines via c++.
# A good choice might be a tuple where the first item is a str identifying a broadcast event
# and the second item is some value: ("collisionStart", 42.)
pass
In c++ implement as many functions as we want that we would expose with bindings
void CPlusPlusExample::doCustomThing(std::string s) {
// do something
}
PyObject* CPlusPlusExample::doCustomGet(std::string s, bool otherArgsArePossible) {
PyObject *p = something;
return p;
}
In c++ create pybind11 binding somehow
PYBIND11_MODULE(my_module, m)
{
py::class_<CPlusPlusExample>(m, "CPlusPlusExample")
.def("DoCustomThing", &CPlusPlusExample::doCustomThing)
.def("DoCustomGet", &CPlusPlusExample::doCustomGet)
}
In python:
op('my_plugin').DoCustomThing("hello")
result = op('my_plugin').DoCustomGet("bark", True)
op('my_plugin').DoNotImplementedThing("fail") # throws error