Array of structs as an attribute of a Perl 6 NativeCall struct

Viewed 207

I'm trying to encapsulate a C struct, one member of which is an array of pointers to structs, and I'm having problems figuring out how to do it.

Let's say the C code looks like this:

struct foo
{
  unsigned char a;
};

struct bar
{
  struct foo *f[5];
};

This kind of code works:

use NativeCall;

class foo is repr('CStruct') {
  has uint8 $.a;
}

class bar is repr('CStruct') {
  has foo $.f1;
  has foo $.f2;
  has foo $.f3;
  has foo $.f4;
  has foo $.f5;
}

but it's terrible.

A CArray is of no use here, because it's just a pointer to an array, not an array of pointers; I can't use something like has A @.a, because a repr('CStruct') doesn't handle that kind of attribute.

Any hint?

1 Answers
Related