16 m.doc() =
"pybind11 cross-module test module";
24 bind_local<ExternalType1>(
m,
"ExternalType1", py::module_local());
25 bind_local<ExternalType2>(
m,
"ExternalType2", py::module_local());
28 m.def(
"raise_runtime_error", []() { PyErr_SetString(PyExc_RuntimeError,
"My runtime error");
throw py::error_already_set(); });
29 m.def(
"raise_value_error", []() { PyErr_SetString(PyExc_ValueError,
"My value error");
throw py::error_already_set(); });
30 m.def(
"throw_pybind_value_error", []() {
throw py::value_error(
"pybind11 value error"); });
31 m.def(
"throw_pybind_type_error", []() {
throw py::type_error(
"pybind11 type error"); });
32 m.def(
"throw_stop_iteration", []() {
throw py::stop_iteration(); });
36 bind_local<LocalType, 1>(
m,
"LocalType", py::module_local())
41 m.def(
"local_value", [](
LocalType &
l) {
return l.
i; });
46 m.def(
"register_nonlocal", [m]() {
47 bind_local<NonLocalType, 0>(
m,
"NonLocalType");
52 py::bind_vector<LocalVec>(
m,
"LocalVec");
53 py::bind_map<LocalMap>(
m,
"LocalMap");
58 m.def(
"register_nonlocal_vec", [m]() {
59 py::bind_vector<NonLocalVec>(
m,
"NonLocalVec");
61 m.def(
"register_nonlocal_map", [m]() {
62 py::bind_map<NonLocalMap>(
m,
"NonLocalMap");
67 py::bind_vector<NonLocalVec2>(
m,
"NonLocalVec2", py::module_local());
69 m.def(
"register_nonlocal_map2", [m]() {
70 py::bind_map<NonLocalMap2>(
m,
"NonLocalMap2", py::module_local(
false));
76 m.def(
"register_mixed_global_local", [m]() {
77 bind_local<MixedGlobalLocal, 200>(
m,
"MixedGlobalLocal", py::module_local());
79 m.def(
"register_mixed_local_global", [m]() {
80 bind_local<MixedLocalGlobal, 2000>(
m,
"MixedLocalGlobal", py::module_local(
false));
89 py::bind_vector<std::vector<int>>(
m,
"VectorInt");
91 m.def(
"load_vector_via_binding", [](std::vector<int> &
v) {
92 return std::accumulate(v.begin(), v.end(), 0);
96 m.def(
"return_self", [](
LocalVec *v) {
return v; });
100 py::class_<pets::Pet>(
m,
"Pet", py::module_local())
103 py::class_<Dog, pets::Pet>(
m,
"Dog")
104 .def(py::init<std::string>());
107 py::class_<MixGL>(
m,
"MixGL", py::module_local()).def(py::init<int>());
108 m.def(
"get_gl_value", [](
MixGL &o) {
return o.
i + 100; });
110 py::class_<MixGL2>(
m,
"MixGL2", py::module_local()).def(py::init<int>());
116 py::bind_vector<std::vector<bool>>(
m,
"VectorBool");
121 m.def(
"missing_header_arg", [](std::vector<float>) { });
122 m.def(
"missing_header_return", []() {
return std::vector<float>(); });
type_map< type_info * > & registered_local_types_cpp()
Works like internals.registered_types_cpp, but for module-local registered types: ...
std::vector< LocalType > LocalVec
static const Line3 l(Rot3(), 1, 1)
PYBIND11_MODULE(pybind11_cross_module_tests, m)
Dog(const std::string &_name, Kind _kind=Kind::Dog)
_W64 unsigned int uintptr_t
LocalBase< 5 > MixedGlobalLocal
Mixed: global first, then local.
Annotation for function names.
Simple class used to test py::local:
LocalBase< 4 > MixedLocalGlobal
Mixed: registered local first, then global.
const std::string & name()