20 m.doc() =
"pybind11 cross-module test module";
28 bind_local<ExternalType1>(
m,
"ExternalType1", py::module_local());
29 bind_local<ExternalType2>(
m,
"ExternalType2", py::module_local());
32 py::register_local_exception<LocalSimpleException>(
m,
"LocalSimpleException");
33 m.def(
"raise_runtime_error", []() {
35 throw py::error_already_set();
37 m.def(
"raise_value_error", []() {
39 throw py::error_already_set();
41 m.def(
"throw_pybind_value_error", []() {
throw py::value_error(
"pybind11 value error"); });
42 m.def(
"throw_pybind_type_error", []() {
throw py::type_error(
"pybind11 type error"); });
43 m.def(
"throw_stop_iteration", []() {
throw py::stop_iteration(); });
44 m.def(
"throw_local_error", []() {
throw LocalException(
"just local"); });
49 std::rethrow_exception(
p);
60 std::rethrow_exception(
p);
69 bind_local<LocalType, 1>(
m,
"LocalType", py::module_local()).def(
"get2", [](
LocalType &
t) {
79 m.def(
"register_nonlocal", [
m]() { bind_local<NonLocalType, 0>(
m,
"NonLocalType"); });
83 py::bind_vector<LocalVec>(
m,
"LocalVec");
84 py::bind_map<LocalMap>(
m,
"LocalMap");
89 m.def(
"register_nonlocal_vec", [
m]() { py::bind_vector<NonLocalVec>(
m,
"NonLocalVec"); });
90 m.def(
"register_nonlocal_map", [
m]() { py::bind_map<NonLocalMap>(
m,
"NonLocalMap"); });
94 py::bind_vector<NonLocalVec2>(
m,
"NonLocalVec2", py::module_local());
96 m.def(
"register_nonlocal_map2",
97 [
m]() { py::bind_map<NonLocalMap2>(
m,
"NonLocalMap2", py::module_local(
false)); });
102 m.def(
"register_mixed_global_local",
103 [
m]() { bind_local<MixedGlobalLocal, 200>(
m,
"MixedGlobalLocal", py::module_local()); });
104 m.def(
"register_mixed_local_global", [
m]() {
105 bind_local<MixedLocalGlobal, 2000>(
m,
"MixedLocalGlobal", py::module_local(
false));
111 m.def(
"local_cpp_types_addr",
115 py::bind_vector<std::vector<int>>(
m,
"VectorInt");
117 m.def(
"load_vector_via_binding",
118 [](std::vector<int> &
v) {
return std::accumulate(
v.begin(),
v.end(), 0); });
121 m.def(
"return_self", [](
LocalVec *
v) {
return v; });
126 explicit Dog(std::string
name) : Pet(std::move(
name)) {}
128 py::class_<pets::Pet>(
m,
"Pet", py::module_local()).def(
"name", &
pets::Pet::name);
130 py::class_<Dog, pets::Pet>(
m,
"Dog").def(py::init<std::string>());
131 m.def(
"pet_name", [](
pets::Pet &
p) {
return p.name(); });
133 py::class_<MixGL>(
m,
"MixGL", py::module_local()).def(py::init<int>());
134 m.def(
"get_gl_value", [](
MixGL &o) {
return o.
i + 100; });
136 py::class_<MixGL2>(
m,
"MixGL2", py::module_local()).def(py::init<int>());
142 py::bind_vector<std::vector<bool>>(
m,
"VectorBool");
147 m.def(
"missing_header_arg", [](
const std::vector<float> &) {});
148 m.def(
"missing_header_return", []() {
return std::vector<float>(); });