Created
May 16, 2022 13:23
-
-
Save Holt59/2f8d8dcbfed96491d3bc440a60d0016f to your computer and use it in GitHub Desktop.
Unpacking C++ type in Python with Pybind11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pybind11/pybind11.h> | |
namespace py = pybind11; | |
struct Size { | |
double width, height; | |
}; | |
PYBIND11_MODULE(demo, m) { | |
py::class_<Size>(m, "Size") | |
.def(py::init<double, double>()) | |
.def_readwrite("width", &Size::width) | |
.def_readwrite("height", &Size::height) | |
.def("__iter__", [](Size const& v) { | |
return py::iter(py::make_tuple(v.width, v.height)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment