I am using Swig to wrap a c library for use with Ruby. There are several functions that return an array of of uint32_t and uint64_t as pointers.
For example something like:
const uint64_t *foo();
const uint32_t *bar();
I feel I should be able to map these into ruby arrays of Integer with a %typemap
, but can't find a good example.
The default mapping is returning a swig pointer , ie #<SWIG::TYPE_p_unsigned_long_long:0x0000000002204200>
including stdint.i via %include "stdint.i"
seems to enable handling the uint64_t, but not the pointers to them.
Update
I tried the following typemap. And it seems to work, is there a better way?
%typemap(out) const uint64_t* {
VALUE arr;
arr = rb_ary_new();
VALUE v1 = INT2NUM(*$1);
VALUE v2 = INT2NUM(*($1+1));
rb_ary_push(arr, v1 );
rb_ary_push(arr, v2 );
$result = arr;
}