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

#include <string>

namespace pybind11_tests {
namespace classh_module_local {

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

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

} // namespace classh_module_local
} // namespace pybind11_tests

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

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

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

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