31 m.def(
"local_value", [](LocalType &
l) {
return l.
i; });
36 bind_local<NonLocalType, 0>(
m,
"NonLocalType")
38 .def(
"get", [](LocalType &
i) {
return i.
i; });
46 m.def(
"register_local_external", [m]() {
47 auto main = py::module_::import(
"pybind11_tests");
49 bind_local<LocalExternal, 7>(
m,
"LocalExternal", py::module_local());
51 throw std::runtime_error(
"test_class not enabled");
57 py::bind_vector<LocalVec>(
m,
"LocalVec");
58 py::bind_map<LocalMap>(
m,
"LocalMap");
60 py::bind_vector<NonLocalVec>(
m,
"NonLocalVec");
61 py::bind_map<NonLocalMap>(
m,
"NonLocalMap");
65 bind_local<NonLocal2, 10>(
m,
"NonLocal2");
66 py::bind_vector<LocalVec2>(
m,
"LocalVec2", py::module_local());
67 py::bind_map<NonLocalMap2>(
m,
"NonLocalMap2", py::module_local(
false));
72 m.def(
"register_mixed_global", [m]() {
73 bind_local<MixedGlobalLocal, 100>(
m,
"MixedGlobalLocal", py::module_local(
false));
75 m.def(
"register_mixed_local", [m]() {
76 bind_local<MixedLocalGlobal, 1000>(
m,
"MixedLocalGlobal", py::module_local());
82 m.def(
"local_cpp_types_addr",
86 m.def(
"load_vector_via_caster",
87 [](std::vector<int>
v) {
return std::accumulate(v.begin(), v.end(), 0); });
90 m.def(
"return_self", [](
LocalVec *v) {
return v; });
95 explicit Cat(std::string
name) : Pet(std::move(name)) {}
97 py::class_<pets::Pet>(
m,
"Pet", py::module_local()).def(
"get_name", &
pets::Pet::name);
99 py::class_<Cat, pets::Pet>(
m,
"Cat").def(py::init<std::string>());
102 py::class_<MixGL>(
m,
"MixGL").def(py::init<int>());
103 m.def(
"get_gl_value", [](
MixGL &o) {
return o.
i + 10; });
105 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)
std::vector< LocalType > LocalVec
const std::string & name() const
static const Line3 l(Rot3(), 1, 1)
LocalBase< 0 > LocalType
Registered with py::module_local in both main and secondary modules:
Array< int, Dynamic, 1 > v
local_internals & get_local_internals()
Works like get_internals, but for things which are locally registered.
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.