nicer code separation, cleanup logic, std::function type caster

This commit is contained in:
Wenzel Jakob
2015-07-30 15:29:00 +02:00
parent a576e6a8ca
commit 281aa0e668
13 changed files with 296 additions and 132 deletions

View File

@@ -9,6 +9,7 @@
*/
#include "example.h"
#include <pybind/functional.h>
class Pet {
@@ -73,6 +74,14 @@ void test_callback3(Example5 *ex, int value) {
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 @@ void init_ex5(py::module &m) {
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>());