I'm currently trying to generate language bindings for ReconstructMe SDK (http://reconstructme.net/) using SWIG. I'm trying to generate low-level bindings for Python, Java and CSharp. The API I'm trying to wrap is a plain C-API and SWIG does a good job wrapping most parts of it automatically, except for one key part.
ReconstructMe SDK declares a pointer to an opaque context object as
typedef struct _reme_context* reme_context_t;
and provides two functions that either create a new or destroy and existing one
// Output a new context
reme_error_t reme_context_create(reme_context_t *c);
// Destroy existing context and set pointer to null
reme_error_t reme_context_destroy(reme_context_t *c);
All other functions of ReMe take a reme_context_t
object as input. For example
reme_error_t reme_context_compile(reme_context_t c);
What SWIG does by default it creates two not convertible types: one for reme_context_t
and one for reme_context_t*
.
What I'd like to achieve is to tell SWIG to reinterpret the reme_context_t
as a pointer to void or something similar that it can handle in all languages and cast to reme_context_t
where necessary.
For example in CSharp a natural way of reinterpreting the above would be to use System.IntPtr
, so that the above turns into
reme_error_t reme_context_create(out System.IntPtr c);
reme_error_t reme_context_destroy(ref System.IntPtr c);
reme_error_t reme_context_compile(System.IntPtr c);
Is there an easy way to do this and to do it in a such a generic way that the SWIG code handles multiple languages?
Thanks in advance, Christoph