On Wed, May 25, 2016 at 8:50 PM, Brandon Allbery <allber...@gmail.com>

> On Wed, May 25, 2016 at 2:41 PM, Fernando Santagata <
> nando.santag...@gmail.com> wrote:
>> gboolean        notify_get_server_info (char **ret_name,
>>                                         char **ret_vendor,
>>                                         char **ret_version,
>>                                         char **ret_spec_version);
>> I think that the four arguments return the information about the system.
>> The problem here is that I'm not an expert on NativeCall, which I'm just
>> beginning to love, and I don't know how to map those char **.
>> What I concocted on the Perl6 side so far is this:
>> sub notify_get_server_info(Str $name is rw, Str $vendor is rw, Str
>> $version is rw, Str $spec_version is rw) returns Bool is native('notify',
>> v4) is export {};
>> The calling program goes like this:
>> my Str ($name, $vendor, $version, $spec_version);
>> if notify_get_server_info($name, $vendor, $version, $spec_version) {
>>   say $name, $vendor, $version, $spec_version;
>> }else{
>>   say 'No server info';
>> }
>> and it prints
>> (Str)(Str)(Str)(Str)
>> So, I get that the mapping is wrong.
> In this case, you need to pass a Pointer[Str] which will be filled in by
> the C function. Just using a Str directly passes a (char *), not a (char
> **), and you ended up with a pointer where rakudo expected characters.

I rewrote the interface like this:

sub notify_get_server_info(Pointer[Str] $name, Pointer[Str] $vendor,
Pointer[Str] $version, Pointer[Str] $spec_version) returns Bool is
native('notify', v4) is export {};

skipping the "rw" role. I can't declare the variables as Str, because I
would get a mismatch error, but I got this result:


Declaring those variables as Pointer[Str] I get:


Should I try to define a class with the repr('CPointer') role to
encapsulate that variable type, or am I off tracks?

Fernando Santagata

Reply via email to