nicer code separation, cleanup logic, std::function type caster
diff --git a/example/example2.cpp b/example/example2.cpp
index 08fdd06..c4a352e 100644
--- a/example/example2.cpp
+++ b/example/example2.cpp
@@ -9,6 +9,7 @@
*/
#include "example.h"
+#include <pybind/stl.h>
class Example2 {
public:
diff --git a/example/example5.cpp b/example/example5.cpp
index 738f9f4..c601ed7 100644
--- a/example/example5.cpp
+++ b/example/example5.cpp
@@ -9,6 +9,7 @@
*/
#include "example.h"
+#include <pybind/functional.h>
class Pet {
@@ -73,6 +74,14 @@
ex->callback(value);
}
+void test_callback4(const std::function<int(int)> &func) {
+ cout << "func(43) = " << func(43)<< std::endl;
+}
+
+std::function<int(int)> test_callback5() {
+ return [](int i) { return i+1; };
+}
+
void init_ex5(py::module &m) {
py::class_<Pet> pet_class(m, "Pet");
pet_class
@@ -89,6 +98,8 @@
m.def("test_callback1", &test_callback1);
m.def("test_callback2", &test_callback2);
m.def("test_callback3", &test_callback3);
+ m.def("test_callback4", &test_callback4);
+ m.def("test_callback5", &test_callback5);
py::class_<Example5>(m, "Example5")
.def(py::init<py::object, int>());
diff --git a/example/example5.py b/example/example5.py
index b119de9..c645af2 100755
--- a/example/example5.py
+++ b/example/example5.py
@@ -22,6 +22,8 @@
from example import test_callback1
from example import test_callback2
from example import test_callback3
+from example import test_callback4
+from example import test_callback5
from example import Example5
def func1():
@@ -43,3 +45,7 @@
callback = MyCallback(3)
test_callback3(callback, 4)
+
+test_callback4(lambda i: i+1)
+f = test_callback5()
+print("func(43) = %i" % f(43))