I wrote a library that makes C++ callable from script languages, but instead of parsing headers it uses C++11 template metaprogramming and type inference, so it always parses exactly what the types are because it runs in the same compiler as your code. Unlike SWIG it is becoming simpler over time as I develop more powerful abstractions and I <i>do</i> understand 100% of how it works (although admittedly you have to have advanced C++ knowledge).<p>Definitely agree with the C++ corner cases thing being a challenge - at times I felt like I was writing another compiler on top of the C++ type system to handle the corner cases. But again, I used powerful abstractions to handle that. For instance, my library uses boost graph library and djikstra's algorithm to handle C++'s tangled web of automatic type conversions.<p><a href="http://github.com/dennisferron/LikeMagic" rel="nofollow">http://github.com/dennisferron/LikeMagic</a>
I've been thinking about how to do this effectively and cleanly for a while now, and I wonder if the right path isn't to use clang to parse the C or C++ code and then generate interfaces from the LLVM IR. As far as I know, all the metadata you need is there, so it might prove simpler than parsing things on your own.
If it shows anything, it is a horrible language design of C++. I wrote a C++ front-end long ago, and it is excruciating.<p>Later, when I had to write native code to speed up Python, I always used plain old C and swig worked flawlessly.
I was one of the maintainers of SWIG's Ruby module during that rewrite he mentions, and I remember how difficult it became for me to really understand how the code worked. I would just hack features into the Ruby module and be glad when they seemed to work, but it always felt like a house of cards. Fortunately some more talented developers took my place when I gave it up.
The SWIG author in question, Dave Beazley, also gave a couple great talks on the Python GIL: <a href="http://www.dabeaz.com/GIL/" rel="nofollow">http://www.dabeaz.com/GIL/</a>
I had a bit of a nightmare with SWIG recently, glad to hear I'm not alone! <a href="http://gaiustech.wordpress.com/2011/08/03/ocaml-bindings-for-coherence-with-swig/" rel="nofollow">http://gaiustech.wordpress.com/2011/08/03/ocaml-bindings-for...</a>