I have开发者_JAVA技巧 such a function in .i
file:
t_demo * t struct_new();
It seems I don't need any typemaps,it just works. After converting I can use it directly:
use test;
$a = test::struct_new;
When is a typemap necessary for swig?
For example, we can create "out" typemap for t_demo and return hash populated with selected members of this struct:
%typemap(out) t_demo {
HV* tmp = newHV();
SV* t_data = newSViv($1.int_field1);
hv_store(tmp, "int_field1", 4, t_data, 0);
$result = sv_2mortal(newRV_noinc((SV*) tmp));
argvi++;
}
Many more uses are documented in swig manual.
精彩评论