I have a C struct with a float*
field. It's considered an array of floats which depict an image. The C struct is part of a library that I'm wrapping by means of SWIG. That pretty much works. I can import the module and create instances of that struct (and others).
The struct looks something like this:
struct MyStruct {
int width;
int height;
float* data;
};
I would like to fill this array from my Python code like
import Foo
d = Foo.MyStruct()
d.data = numpy.zeros(640*480)
This does not work out of the box. I'm getting a TypeError
stating:
in method 'MyStruct_data_set', argument 2 of type 'float *'
in a SWIG internal method called _swig_setattr_nondynamic
I suppose I'll have to do something with the pointer in order to make clear that it's a float array of arbitrary size.
What is it that I have to do, supposedly in the module .i
file, to make the code above working?
/edit: as requested, the .i
file is no more than this:
%module Foo
%{
#include <Foo.h>
%}
%include Foo.h
Pretty basic. I'm completely new to SWIG.