To give it that pythonic look, I'd use a combination of boost::python::extract
, tuple
's and list
's. Here is a sketch:
static bpy::list py_search(bpy::tuple start, bpy::tuple goal) {
// optionally check that start and goal have the required
// size of 2 using bpy::len()
// convert arguments and call the C++ search method
std::array<double,2> _start = {bpy::extract<double>(start[0]), bpy::extract<double>(start[1])};
std::array<double,2> _goal = {bpy::extract<double>(goal[0]), bpy::extract<double>(goal[1])};
std::vector<std::array<double,2>> cxx_retval = search(_start, _goal);
// converts the returned value into a list of 2-tuples
bpy::list retval;
for (auto &i : cxx_retval) retval.append(bpy::make_tuple(i[0], i[1]));
return retval;
}
Then the bindings would look like this:
bpy::def("search", &py_search);