mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
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:
@@ -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; });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user