[C++-sig] call C-functions (by reference) from Python (using Boost.Python)
Roman Yakovenko
roman.yakovenko at gmail.com
Fri Dec 8 18:51:37 CET 2006
On 12/8/06, Lutz Lauterbach <Lutz.Lauterbach at qimonda.com> wrote:
> But now I face another hurdle: I also want to return arrays from C. Using the
> above scheme:
>
> void jz_array(float a[], float b[]){
> a[0]=0;a[1]=1;a[2]=2;
> b[0]=0;b[1]=-1;b[2]=-2;
> return;
> }
> //////////////////////////////////
> #include <boost/python.hpp>
> namespace bp = boost::python;
> bp::tuple py_jz_array(){
> float v1[3];float v2[3];
> jz_array(v1, v2);
> return bp::make_tuple(v1,v2);
> }
> using namespace bp;
> BOOST_PYTHON_MODULE(test)
> { def("jz_array",py_jz_array);}
>
> does not work. It comiples, but when calling the function "jz_array" from
> Python it says
>
> >>> jz_array()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: No to_python (by-value) converter found for C++ type: float [3]
>
> Do you know any solution?
Take a look on fixed_input_array or fixed_output_array function within a file I
attached previously in this thread. You can find implementation of
helper functions here: http://tinyurl.com/ydpjak
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list