开发者

When is a typemap necessary for swig?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜