1

Trying to pass a C struct in and out of Java. Everything works except I cannot figure out how to read and write the elements of the array inside the structure. I read about memberin typemap but I am sure I am still not using it right. My module file looks like this:

%include "typemaps.i"

%typemap(memberin) uint8_t [8] {
  int i;
  for (i = 0; i < 8; i++) {
    $1[i] = $input[i];
  }
}

typedef struct
{
   uint8_t myarray[8];
   int myvar;
} MyStruct;

In Java, I was hoping I would be able to use the generated MyArray object like this:

MyStruct s = new MyStruct();
SWIGTYPE_p_uint8_t[] myarray = s.getMyarray();
s.setMyarray(myarray);

But instead, the generated getMyarray() returns SWIGTYPE_p_uint8_t rather than an array of it. The same applies for the argument of s.setMyArray.

Can anyone please help?

Coconha
  • 11
  • 2
  • Just realised similar question was asked before, but no answer so far. https://stackoverflow.com/questions/35203463/swig-getters-setters-for-an-array-of-struct-dont-return-expect-an-array-of-pro – Coconha May 22 '19 at 10:23

0 Answers0