11#include <pybind11/stl.h>
12#include <pybind11/stl_bind.h>
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");
48 if (py::hasattr(
main,
"class_")) {
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",
83 []() {
return (uintptr_t) &py::detail::get_local_internals().registered_types_cpp; });
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>());
Simple class used to test py::local:
const std::string & name() const
int main(int argc, char *argv[])
std::vector< LocalType > LocalVec
LocalBase< 4 > MixedLocalGlobal
Mixed: registered local first, then global.
LocalBase< 0 > LocalType
Registered with py::module_local in both main and secondary modules:
py::class_< T > bind_local(Args &&...args)
LocalBase< 5 > MixedGlobalLocal
Mixed: global first, then local.
#define TEST_SUBMODULE(name, variable)
Annotation for function names.