mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 03:31:36 +01:00
pybind11: fix and generalize example
This commit is contained in:
22
userland/libs/pybind11/class_test.cpp
Normal file
22
userland/libs/pybind11/class_test.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <string>
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
struct ClassTest {
|
||||
ClassTest(const std::string &name) : name(name) { }
|
||||
void setName(const std::string &name_) { name = name_; }
|
||||
const std::string &getName() const { return name; }
|
||||
std::string name;
|
||||
};
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
PYBIND11_PLUGIN(class_test) {
|
||||
py::module m("my_module", "pybind11 example plugin");
|
||||
py::class_<ClassTest>(m, "ClassTest")
|
||||
.def(py::init<const std::string &>())
|
||||
.def("setName", &ClassTest::setName)
|
||||
.def("getName", &ClassTest::getName)
|
||||
.def_readwrite("name", &ClassTest::name);
|
||||
return m.ptr();
|
||||
}
|
||||
Reference in New Issue
Block a user