functional: support bound methods

If a bound std::function is invoked with a bound method, the implicit
bound self is lost because we use `detail::get_function` to unbox the
function.  This commit amends the code to use py::function and only
unboxes in the special is-really-a-c-function case.  This makes bound
methods stay bound rather than unbinding them by forcing extraction of
the c function.
This commit is contained in:
Jason Rhinelander
2017-04-24 12:29:42 -04:00
parent 7653a115bd
commit a01b6b805c
4 changed files with 35 additions and 11 deletions

View File

@@ -179,4 +179,9 @@ test_initializer callbacks([](py::module &m) {
f(x); // lvalue reference shouldn't move out object
return x.valid; // must still return `true`
});
struct CppBoundMethodTest {};
py::class_<CppBoundMethodTest>(m, "CppBoundMethodTest")
.def(py::init<>())
.def("triple", [](CppBoundMethodTest &, int val) { return 3 * val; });
});