You can very easily add extra methods to a type which has been forward declared in SWIG by giving it an empty definition in the interface, e.g.
test.h:
// Forward declare foo
struct foo;
test.i:
%module test
// Tell SWIG to wrap foo "properly", but that you don't know anything about it:
struct foo { };
%include "test.h"
%extend foo {
void bar() {
// Do stuff, probably with $self, here
}
}
The key is that in the interface file you're not actually writing C or C++ in the normal sense, you're telling SWIG what types and what parts of each type to wrap.
Since you will presumably be relying on the library to create and destroy instances you'll also want to add:
%nodefaultctor foo;
%nodefaultdtor foo;
In the interface file to suppress the constructor/destructor generation and force it to go through the library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…