25 .def(
"get3", [](LocalType &t) {
return t.
i + 3; })
28 m.def(
"local_value", [](LocalType &l) {
return l.
i; });
33 bind_local<NonLocalType, 0>(m,
"NonLocalType")
35 .def(
"get", [](LocalType &
i) {
return i.
i; })
43 m.def(
"register_local_external", [m]() {
44 auto main = py::module::import(
"pybind11_tests");
48 else throw std::runtime_error(
"test_class not enabled");
53 py::bind_vector<LocalVec>(m,
"LocalVec");
54 py::bind_map<LocalMap>(m,
"LocalMap");
56 py::bind_vector<NonLocalVec>(m,
"NonLocalVec");
57 py::bind_map<NonLocalMap>(m,
"NonLocalMap");
61 bind_local<NonLocal2, 10>(m,
"NonLocal2");
68 m.def(
"register_mixed_global", [m]() {
69 bind_local<MixedGlobalLocal, 100>(m,
"MixedGlobalLocal",
py::module_local(
false));
71 m.def(
"register_mixed_local", [m]() {
72 bind_local<MixedLocalGlobal, 1000>(m,
"MixedLocalGlobal",
py::module_local());
81 m.def(
"load_vector_via_caster", [](std::vector<int> v) {
82 return std::accumulate(v.begin(), v.end(), 0);
86 m.def(
"return_self", [](
LocalVec *v) {
return v; });
94 .def(py::init<std::string>());
98 m.
def(
"get_gl_value", [](
MixGL &o) {
return o.
i + 10; });
py::class_< T > bind_local(Args &&...args)
test_initializer local_bindings("local_bindings", test_submodule_local_bindings)
std::vector< LocalType > LocalVec
Cat(const std::string &_name, Kind _kind=Kind::Cat)
type_map< type_info * > & registered_local_types_cpp()
Works like internals.registered_types_cpp, but for module-local registered types: ...
const std::string & name()
LocalBase< 0 > LocalType
Registered with py::module_local in both main and secondary modules:
LocalBase< 5 > MixedGlobalLocal
Mixed: global first, then local.
#define TEST_SUBMODULE(name, variable)
LocalBase< 4 > MixedLocalGlobal
Mixed: registered local first, then global.
bool typename Extra class_ & def(const char *name_, Func &&f, const Extra &... extra)
Simple class used to test py::local:
bool hasattr(handle obj, handle name)
Annotation that marks a class as local to the module: