Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pybind11/pybind11.h>
- #include <pybind11/embed.h>
- #include <iostream>
- namespace py = pybind11;
- PYBIND11_EMBEDDED_MODULE(testmodule, m)
- {
- m.def("start", [](py::module& foo) {
- try {
- py::module bar = foo.attr("bar");
- std::cout << "ok\n";
- } catch (py::error_already_set const& e) {
- std::cerr << "error" << e.what() << '\n';
- }
- });
- }
- int main()
- {
- py::scoped_interpreter guard{};
- try {
- py::exec(R"(\
- import testmodule
- import foo
- testmodule.start(foo)
- )");
- } catch (py::error_already_set& e) {
- std::cerr << e.what() << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement