mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
pybind11: keep files in tree just for future reference, not properly automated yet
This commit is contained in:
24
userland/libs/pybind11/class.cpp
Normal file
24
userland/libs/pybind11/class.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <pybind11/pybind11.h>
|
||||||
|
|
||||||
|
struct Pet {
|
||||||
|
Pet(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(example) {
|
||||||
|
py::module m("example", "pybind11 example plugin");
|
||||||
|
|
||||||
|
py::class_<Pet>(m, "Pet")
|
||||||
|
.def(py::init<const std::string &>())
|
||||||
|
.def("setName", &Pet::setName)
|
||||||
|
.def("getName", &Pet::getName);
|
||||||
|
|
||||||
|
return m.ptr();
|
||||||
|
}
|
||||||
8
userland/libs/pybind11/class_test_main.py
Executable file
8
userland/libs/pybind11/class_test_main.py
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import class_test
|
||||||
|
|
||||||
|
my_class_test = class_test.ClassTest("abc");
|
||||||
|
print(my_class_test.getName())
|
||||||
|
my_class_test.setName("012")
|
||||||
|
print(my_class_test.getName())
|
||||||
4
userland/libs/pybind11/test.sh
Executable file
4
userland/libs/pybind11/test.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu
|
||||||
|
g++ -O3 -Wall -shared -std=c++11 -fPIC class_test.cpp -o class_test`python3-config --extension-suffix` -I /usr/include/python3.6m
|
||||||
|
./class_test_main.py
|
||||||
Reference in New Issue
Block a user