correction regarding macros:

myheader.h:
#define MEX_INFORMATION_VERSION 1

interface file myheader.i:
%{
%include "myheader.h"
%}
%include myheader.h

generated d file will contain:

int MEX_INFORMATION_VERSION() @property {
  auto ret = swig.mex_im.swig_mex_MEX_INFORMATION_VERSION_get();
  return ret;
}

which allows one to use the macro from D. Certainly not the best way (an enum would be preferable) but it works. Again, swig could be improved. Also if static libraries could be generated, the overhead above wouldn't be such a big deal with link time optimization.

For functional macros, I'm not sure, but once can write a C function that calls the macro, and then swig will convert to D function. Ideally, swig would directly convert it to a templated function.


I think maintaining a repository of interface files would be a better idea than maintaining manually converted C files. The former would be much smaller & easier to maintain, and for 99% cases stay in sync with library updates. The latter would end up as a graveyard of never up to date partially-portable C ports that no-one will want to maintain.


Reply via email to