Trying to interface with a C library that takes a struct with a bunch of pointers to functions it calls at various points.
something like this:
struct callbacks {
int (*foo)(int);
int (*bar)(int);
}
int set_callbacks(callbacks *cbs);
I can make my callbacks:
sub foo-callback(int32 --> int32) {...}
sub bar-callback(int32 --> int32) {...}
It would be cool if this worked:
class Callbacks is repr<CStruct>
{
has &.foo (int32 --> int32);
has &.bar (int32 --> int32);
}
but it doesn't. I'm trying to do something with:
class Callbacks is repr<CStruct>
{
has Pointer $.foo;
has Pointer $.bar;
}
and set those to nativecast(Pointer, &foo-callback)
or some such, but I can't
seem to force them in there.
Is there any way to do this beyond writing a little C function that takes all the Perl 6 function pointers and plugging them in the structure in C?