开发者

Python SWIG arrays

I am wrapping a C module with SWIG for Python. Is there any 开发者_开发问答way to turn all Python lists/tuples whose members are all of the same type (same kind of Swig object) to C arrays?


Typemaps. What you are most likely looking for is an "in" typemap, which maps Python types to C types. The declaration looks something like this:

%typemap(in) { /* C code to convert Python tuple object to C array */ }

Inside the typemap code you can use the variable $input to reference the PyObject* to convert, and assign your converted C array to $1.

http://docs.python.org/c-api/ has information on the Python/C API, which you'll need to unpack the tuple to get the items and convert them to C.

http://www.swig.org/Doc1.3/Typemaps.html has the SWIG documentation for typemaps.

The documentation can be hard to understand at first, so take a look at some example typemaps in /share. carrays.i in that directory might also serve as a good starting point.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜