classh_module_local_2.cpp 908 Bytes
Newer Older
1
// Identical to classh_module_local_1.cpp, except 1 replaced with 2.
2
#include <pybind11/pybind11.h>
3
#include <pybind11/smart_holder.h>
4
5
6
7
8
9

#include <string>

namespace pybind11_tests {
namespace classh_module_local {

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
17
18

} // namespace classh_module_local
} // namespace pybind11_tests

19
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_module_local::atyp)
20
21
22
23
24

PYBIND11_MODULE(classh_module_local_2, m) {
    namespace py = pybind11;
    using namespace pybind11_tests::classh_module_local;

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
}