[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Current best practice for C++ exception handling
- From: Miles Bader <miles@...>
- Date: Sat, 13 Mar 2010 11:42:03 +0900
Gaspard Bucher <gaspard@teti.ch> writes:
> * you have to write receipts
> * you cannot parse the inline C++ documentation to generate the docs
> * it's a compiled piece of code (not that easy to adapt)
> * you have to learn yet another language just for the bindings
Hm, swig's interface definition language is basically C++; you can in
theory just feed it your existing .h files and generate an interface
from them.
In practice you usually don't want to do this, but instead copy the C++
definitions and tweak them a bit for swig. Among the reason for this:
(1) Often you don't really want the [Lua/...] interface to be _exactly_
the same. You want it to mesh with your target language well, and
sometimes C++ interfaces don't, and need a bit of adaptation
(though the bulk of the interface remains identical).
For instance, C++ doesn't have multiple return values, so a C++
method may say "void method (int arg, int &result1, int &result2)"
-- but in Lua, you'd really rather just get result1 and result2 as
return values.
In other cases, you'd really rather just suppress a particular
method in the Lua interface, and replace it with a small shim
method that better matches Lua (generally these are not really Lua
specific, but simply more suited to scripting language in general).
(2) Swig's C++ parser, while decent, isn't perfect, and sometimes needs
help (e.g., you have to tell it which template instantiations are
important).
If you have a better parser, I imagine you can maybe avoid (2), but
problem (1) seems somewhat inherent to the task of interfacing
dissimilar languages. Is doxygen annotation so expressive that it helps
solve this problem? (doxygen is after all, "another language" :)
-Miles
--
Somebody has to do something, and it's just incredibly pathetic that it
has to be us. -- Jerry Garcia