wxC & wxD
Johannes Pfau
spam at example.com
Tue Nov 29 03:04:44 PST 2011
Gour wrote:
>> Btw, Johannes Pfau wrapped most of TagLib with SWIG and said the
>> wrapping process was frustrating.
>
>Well, I'd like to hear more about his experiences...Which version of
>SWIG he used?
I think the last version I used was a svn snapshot after the 2.0.2
release. It's not that using swig was especially frustrating, but the
TagLib C++ API offers little over the much simpler C API. So I thought
wrapping the complete C++ API just wasn't worth it.
Some problems I had with swig:
As I was new to swig I had no idea how to organize a big project
consisting of multiple C++ headers. There are questions like include
vs. import; simply editing the C++ headers vs. including the headers and
placing rename directives etc. into own files; how to organize the
project, so that changes to the c++ library can be merged easily...
The swig manual is *huge* and works well as a reference, but a simple
introduction tutorial doesn't exist AFAIK.
It took me some time to get template instances working, somehow I
didn't understand the syntax or whatever.
And there are some 'cosmetic issues' that don't matter for
functionality, but I found these to be annoying:
* IIRC free functions or variables/properties always go into the main
file and it's not possible to place those into a specific namespace
* I think it's the same for template instances and hand written code,
but I'm not sure
* Namespace duplication: Namespaces look like this: "TagLib.APE.APE".
This is needed to support some corner cases where C++
namespaces wouldn't map well to D namespaces otherwise. But
for simple namespaces I'd like to have proper namespaces
("TagLib.APE")
* swig always generates a main module, and IIRC it even has to be a
toplevel module (TagLibBase, not TagLib.Base). And as D doesn't allow
packages and modules to have the same name, it wasn't possible to
simply name this main module "TagLib", so I named it "TagLibD"
instead. But this still sucks, as your namespaces then look like this:
TagLibD
TagLib.TagLib
TagLib.APE.APE
TagLib.ID3v2.ID3v2
Having two different toplevel namespaces especially annoyed me.
However, I'd nevertheless say swig is the best solution to wrap a C++
project unless there's a manually written, well supported C API.
Also, in case you're interested, the source for that TagLib swig
wrapper is here:
https://github.com/jpf91/TagLibD/
--
Johannes Pfau
More information about the Digitalmars-d
mailing list