|
8 | 8 | #include <boost/python/class.hpp> |
9 | 9 | #include <boost/ref.hpp> |
10 | 10 | #include <boost/python/ptr.hpp> |
| 11 | +#include <boost/python/return_value_policy.hpp> |
| 12 | +#include <boost/python/reference_existing_object.hpp> |
11 | 13 |
|
12 | 14 | using namespace boost::python; |
13 | 15 |
|
@@ -48,6 +50,16 @@ void apply_void_X_ref(PyObject* f, X& x) |
48 | 50 | returning<void>::call(f, boost::ref(x)); |
49 | 51 | } |
50 | 52 |
|
| 53 | +X& apply_X_ref_pyobject(PyObject* f, PyObject* obj) |
| 54 | +{ |
| 55 | + return returning<X&>::call(f, obj); |
| 56 | +} |
| 57 | + |
| 58 | +X* apply_X_ptr_pyobject(PyObject* f, PyObject* obj) |
| 59 | +{ |
| 60 | + return returning<X*>::call(f, obj); |
| 61 | +} |
| 62 | + |
51 | 63 | void apply_void_X_cref(PyObject* f, X const& x) |
52 | 64 | { |
53 | 65 | returning<void>::call(f, boost::cref(x)); |
@@ -63,6 +75,21 @@ void apply_void_X_deep_ptr(PyObject* f, X* x) |
63 | 75 | returning<void>::call(f, x); |
64 | 76 | } |
65 | 77 |
|
| 78 | +char const* apply_cstring_cstring(PyObject* f, char const* s) |
| 79 | +{ |
| 80 | + return returning <char const*>::call(f, s); |
| 81 | +} |
| 82 | + |
| 83 | +char const* apply_cstring_pyobject(PyObject* f, PyObject* s) |
| 84 | +{ |
| 85 | + return returning <char const*>::call(f, s); |
| 86 | +} |
| 87 | + |
| 88 | +char apply_char_char(PyObject* f, char c) |
| 89 | +{ |
| 90 | + return returning <char>::call(f, c); |
| 91 | +} |
| 92 | + |
66 | 93 | int X::counter; |
67 | 94 |
|
68 | 95 | BOOST_PYTHON_MODULE_INIT(callbacks_ext) |
@@ -75,6 +102,17 @@ BOOST_PYTHON_MODULE_INIT(callbacks_ext) |
75 | 102 | .def("apply_void_X_cref", apply_void_X_cref) |
76 | 103 | .def("apply_void_X_ptr", apply_void_X_ptr) |
77 | 104 | .def("apply_void_X_deep_ptr", apply_void_X_deep_ptr) |
| 105 | + |
| 106 | + .def("apply_X_ptr_pyobject", apply_X_ptr_pyobject |
| 107 | + , return_value_policy<reference_existing_object>()) |
| 108 | + |
| 109 | + .def("apply_X_ref_pyobject", apply_X_ref_pyobject |
| 110 | + , return_value_policy<reference_existing_object>()) |
| 111 | + |
| 112 | + .def("apply_cstring_cstring", apply_cstring_cstring) |
| 113 | + .def("apply_cstring_pyobject", apply_cstring_pyobject) |
| 114 | + .def("apply_char_char", apply_char_char) |
| 115 | + |
78 | 116 | .add( |
79 | 117 | class_<X>("X") |
80 | 118 | .def_init(args<int>()) |
|