Neither do I (swig/cmake), but i think i can try to construct proper patch for community repo (not much of work). SWIG wrapping looks like below, and is convenient to use because it *should* bridge types of both languages properly (i.e const char* might be string).
There are the downsides though - as You can see there are bridge functions which might have memory allocations which isn't cool anymore. I'm not sure if it's affordable to have these in graphics engine. Since I still don't feel confident in this area, could anyone hint me if it's worth to pay this performance cost for convenience?
Lastly, i would see this like Bindings -> D -> swig -> CMakeLists.txt . And about other languages, should i add similar directories for other
supported languages or it's not interesting enough to support them in horde3d?
Ps. If someone else already played with cmake / swig and would like to make it work, just tell me so i won't double efforts
Code:
(...)
// Support for throwing D exceptions from C/C++.
typedef enum {
SWIG_DException = 0,
SWIG_DIllegalArgumentException,
SWIG_DIllegalElementException,
SWIG_DIOException,
SWIG_DNoSuchElementException,
} SWIG_DExceptionCodes;
typedef void (* SWIG_DExceptionCallback_t)(const char *);
typedef struct {
SWIG_DExceptionCodes code;
SWIG_DExceptionCallback_t callback;
} SWIG_DException_t;
static SWIG_DException_t SWIG_d_exceptions[] = {
{ SWIG_DException, NULL },
{ SWIG_DIllegalArgumentException, NULL },
{ SWIG_DIllegalElementException, NULL },
{ SWIG_DIOException, NULL },
{ SWIG_DNoSuchElementException, NULL }
};
(..)
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGRegisterExceptionCallbacks_Horde3D(
SWIG_DExceptionCallback_t exceptionCallback,
SWIG_DExceptionCallback_t illegalArgumentCallback,
SWIG_DExceptionCallback_t illegalElementCallback,
SWIG_DExceptionCallback_t ioCallback,
SWIG_DExceptionCallback_t noSuchElementCallback) {
SWIG_d_exceptions[SWIG_DException].callback = exceptionCallback;
SWIG_d_exceptions[SWIG_DIllegalArgumentException].callback = illegalArgumentCallback;
SWIG_d_exceptions[SWIG_DIllegalElementException].callback = illegalElementCallback;
SWIG_d_exceptions[SWIG_DIOException].callback = ioCallback;
SWIG_d_exceptions[SWIG_DNoSuchElementException].callback = noSuchElementCallback;
}
// Callback for returning strings to D without leaking memory.
typedef char * (* SWIG_DStringHelperCallback)(const char *);
static SWIG_DStringHelperCallback SWIG_d_string_callback = NULL;
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGRegisterStringCallback_Horde3D(SWIG_DStringHelperCallback callback) {
SWIG_d_string_callback = callback;
}
/* Contract support. */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
#ifdef __cplusplus
extern "C" {
#endif
Code:
SWIGEXPORT int D_H3DRootNode_get() {
int jresult ;
H3DNode result;
result = (H3DNode)(H3DNode)H3DRootNode;
jresult = result;
return jresult;
}
SWIGEXPORT void * D_new_H3DOptions() {
void * jresult ;
struct H3DOptions *result = 0 ;
result = (struct H3DOptions *)calloc(1, sizeof(struct H3DOptions));
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void D_delete_H3DOptions(void * jarg1) {
struct H3DOptions *arg1 = (struct H3DOptions *) 0 ;
arg1 = (struct H3DOptions *)jarg1;
free((char *) arg1);
}
Code:
SWIGEXPORT char * D_h3dGetResName(int jarg1) {
char * jresult ;
H3DRes arg1 ;
char *result = 0 ;
arg1 = (H3DRes)jarg1;
result = (char *)h3dGetResName(arg1);
jresult = SWIG_d_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT int D_h3dGetNextResource(int jarg1, int jarg2) {
int jresult ;
int arg1 ;
H3DRes arg2 ;
H3DRes result;
arg1 = (int)jarg1;
arg2 = (H3DRes)jarg2;
result = (H3DRes)h3dGetNextResource(arg1,arg2);
jresult = result;
return jresult;
}
SWIGEXPORT int D_h3dFindResource(int jarg1, char * jarg2) {
int jresult ;
int arg1 ;
char *arg2 = (char *) 0 ;
H3DRes result;
arg1 = (int)jarg1;
arg2 = (char *)jarg2;
result = (H3DRes)h3dFindResource(arg1,(char const *)arg2);
jresult = result;
return jresult;
}
SWIGEXPORT int D_h3dAddResource(int jarg1, char * jarg2, int jarg3) {
int jresult ;
int arg1 ;
char *arg2 = (char *) 0 ;
int arg3 ;
H3DRes result;
arg1 = (int)jarg1;
arg2 = (char *)jarg2;
arg3 = (int)jarg3;
result = (H3DRes)h3dAddResource(arg1,(char const *)arg2,arg3);
jresult = result;
return jresult;
}
SWIGEXPORT int D_h3dCloneResource(int jarg1, char * jarg2) {
int jresult ;
H3DRes arg1 ;
char *arg2 = (char *) 0 ;
H3DRes result;
arg1 = (H3DRes)jarg1;
arg2 = (char *)jarg2;
result = (H3DRes)h3dCloneResource(arg1,(char const *)arg2);
jresult = result;
return jresult;
}
SWIGEXPORT int D_h3dRemoveResource(int jarg1) {
int jresult ;
H3DRes arg1 ;
int result;
arg1 = (H3DRes)jarg1;
result = (int)h3dRemoveResource(arg1);
jresult = result;
return jresult;
}