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");
46 bind_local<LocalExternal, 7>(
m,
"LocalExternal", py::module_local());
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");
62 py::bind_vector<LocalVec2>(
m,
"LocalVec2", py::module_local());
63 py::bind_map<NonLocalMap2>(
m,
"NonLocalMap2", py::module_local(
false));
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; });
90 py::class_<pets::Pet>(
m,
"Pet", py::module_local())
93 py::class_<Cat, pets::Pet>(
m,
"Cat")
94 .def(py::init<std::string>());
97 py::class_<MixGL>(
m,
"MixGL").def(py::init<int>());
98 m.def(
"get_gl_value", [](
MixGL &o) {
return o.
i + 10; });
100 py::class_<MixGL2>(
m,
"MixGL2").def(py::init<int>());
TEST_SUBMODULE(local_bindings, m)
py::class_< T > bind_local(Args &&...args)
bool hasattr(handle obj, handle name)
int main(int argc, char **argv)
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)
LocalBase< 0 > LocalType
Registered with py::module_local in both main and secondary modules:
Array< double, 1, 3 > e(1./3., 0.5, 2.)
_W64 unsigned int uintptr_t
LocalBase< 5 > MixedGlobalLocal
Mixed: global first, then local.
Annotation for function names.
Simple class used to test py::local:
Cat(const std::string &_name, Kind _kind=Kind::Cat)
LocalBase< 4 > MixedLocalGlobal
Mixed: registered local first, then global.
const std::string & name()