class_sh_module_local_2.cpp 926 Bytes
Newer Older
1
// Identical to class_sh_module_local_1.cpp, except 1 replaced with 2.
2
#include <pybind11/pybind11.h>
3
#include <pybind11/smart_holder.h>
4
5
6
7

#include <string>

namespace pybind11_tests {
8
namespace class_sh_module_local {
9

10
11
struct atyp { // Short for "any type".
    std::string mtxt;
12
13
};

14
std::string get_mtxt(const atyp &obj) { return obj.mtxt; }
15

16
} // namespace class_sh_module_local
17
18
} // namespace pybind11_tests

19
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_module_local::atyp)
20

21
PYBIND11_MODULE(class_sh_module_local_2, m) {
22
    namespace py = pybind11;
23
    using namespace pybind11_tests::class_sh_module_local;
24

25
    py::class_<atyp, py::smart_holder>(m, "atyp", py::module_local())
26
27
28
        .def(py::init([](const std::string &mtxt) {
            atyp obj;
            obj.mtxt = mtxt;
29
30
            return obj;
        }))
31
        .def("tag", [](const atyp &) { return 2; });
32

33
    m.def("get_mtxt", get_mtxt);
34
}