Ejemplo n.º 1
0
void init_ex9(py::module &m) {
    py::module m_sub = m.def_submodule("submodule");
    m_sub.def("submodule_func", &submodule_func);

    py::class_<A>(m_sub, "A")
        .def(py::init<int>())
        .def("__repr__", &A::toString);

    py::class_<B>(m_sub, "B")
        .def(py::init<>())
        .def("get_a1", &B::get_a1, "Return the internal A 1", py::return_value_policy::reference_internal)
        .def("get_a2", &B::get_a2, "Return the internal A 2", py::return_value_policy::reference_internal)
        .def_readwrite("a1", &B::a1)  // def_readonly uses an internal reference return policy by default
        .def_readwrite("a2", &B::a2);

    m.attr("OD") = py::module::import("collections").attr("OrderedDict");
}
Ejemplo n.º 2
0
void init_ex4(py::module &m) {
    m.def("test_function", &test_function1);
    m.def("test_function", &test_function2);
    m.def("test_function", &test_function3);
    m.attr("some_constant") = py::int_(14);

    py::enum_<EMyEnumeration>(m, "EMyEnumeration")
        .value("EFirstEntry", EFirstEntry)
        .value("ESecondEntry", ESecondEntry)
        .export_values();

    py::class_<Example4> ex4_class(m, "Example4");
    ex4_class.def_static("test_function", &Example4::test_function);
    py::enum_<Example4::EMode>(ex4_class, "EMode")
        .value("EFirstMode", Example4::EFirstMode)
        .value("ESecondMode", Example4::ESecondMode)
        .export_values();

    m.def("return_bytes", &return_bytes);
    m.def("print_bytes", &print_bytes);
}