Yingjie Lan, 28.04.2010 05:53:
From: Stefan Behnel
Yingjie Lan, 27.04.2010 08:30:
Is it possible to use SWIG to parse C/C++, and provide
an interface for
me to generate some code? I thought it might be good
to have SWIG help
generate expy files, then generate the python
extension via expy.

There have been similar discussions on the Cython mailing
list (you might want to search the archives). The main theme
seems to be that clang provides a suitable parser, and
several people have used it to write up a code generator for
their specific needs (you might want to look at those).

Thank you very much, I will take a look at this.
BTW, is there a similar project going on for Cython?

Not from the side of the core developers. As I said, some users have grown their own tools, but nothing generally usable has been contributed so far.

Anyway, the use case isn't as important as one might think. The only reason why one would want to use an automated wrapper generator is because a huge API needs to get wrapped quickly (such as Qt or GTK, for example), and performance doesn't really matter (like for a GUI toolkit).

Most people want a wrapper that is fast, efficient and well usable from Python code. In most cases, one, two or all of these three requirements will prohibit the use of a wrapper generator like SWIG or Boost, so you'll eventually end up writing a wrapper manually anyway. For Cython, such a tool would mostly generate the .pxd declarations and potentially a one-time skeleton that users would then adapt to their needs, and that they would likely rewrite broadly. C APIs usually don't fit Python very well, and C++ APIs only do so in rare cases.

Even if the wrapped C/C++ API is big, it can often benefit from a smaller, more high-level wrapper, rather than transferring all low-level quirks into Python space and annoying users with them. A keyword argument here and there is much better than yet another function, and any manual memory management is straight out in the first place.

Stefan

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to