Skip to content

Commit ddb75d9

Browse files
committed
added cpp files
1 parent 5f891ec commit ddb75d9

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

bindings.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <pybind11/pybind11.h>
2+
3+
namespace py = pybind11;
4+
5+
PYBIND11_PLUGIN(cmake_example)
6+
{
7+
py::module m("cmake_example", R"pbdoc(
8+
Pybind11 example plugin
9+
-----------------------
10+
.. currentmodule:: cmake_example
11+
.. autosummary::
12+
:toctree: _generate
13+
add
14+
subtract
15+
)pbdoc");
16+
17+
m.def("add", &add, R"pbdoc(
18+
Add two numbers
19+
Some other explanation about the add function.
20+
)pbdoc");
21+
22+
m.def("subtract", &subtract, R"pbdoc(
23+
Subtract two numbers
24+
Some other explanation about the subtract function.
25+
)pbdoc");
26+
27+
#ifdef VERSION_INFO
28+
m.attr("__version__") = py::str(VERSION_INFO);
29+
#else
30+
m.attr("__version__") = py::str("dev");
31+
#endif
32+
33+
return m.ptr();
34+
}

python_cpp_example/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "main.hpp"
2+
3+
int add(int i, int j)
4+
{
5+
return i + j;
6+
}
7+
8+
int subtract(int i, int j)
9+
{
10+
return i - j;
11+
}

python_cpp_example/main.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int add(int i, int j);
2+
3+
int subtract(int i, int j);

0 commit comments

Comments
 (0)