I'm trying to use NativeCall to interact with some C functions.
For one case, I need to pass in pointers that get updated by the function, so it wants a pointer to a pointer, 'void **'.
I tried it like this:
class Foo
{
has Pointer $.first;
has Pointer $.last;
sub somefunc(Pointer is rw, Pointer is rw, Str) is native { * }
method myfunc(Str $arg) {
somefunc($!first, $!last, $arg);
}
}
It doesn't work. The pointers don't get updated by the function.
Since a C array is basically a pointer to a pointer, I can fake it like this:
class Foo
{
has Pointer $.first;
has Pointer $.last;
sub somefunc(CArray[Pointer], CArray[Pointer], Str) is native { * }
method myfunc(Str $arg) {
my $first = CArray[Pointer].new($!first);
my $last = CArray[Pointer].new($!last);
somefunc($first, $last, $arg);
$!first = $first[0];
$!last = $last[0];
}
}
It works fine like this. It just seems like the "is rw" should force the pointer to pointer and it should work the first way.
What am I doing wrong?