Skip to content

Instantly share code, notes, and snippets.

@taboege
Created May 5, 2019 11:43
Show Gist options
  • Save taboege/2e95ce969d26d00342669723c1a11dd1 to your computer and use it in GitHub Desktop.
Save taboege/2e95ce969d26d00342669723c1a11dd1 to your computer and use it in GitHub Desktop.
NativeCall callback signature syntax?
#!/usr/bin/env perl6
use NativeCall;
sub qsort(
CArray[int32] $base,
size_t $count,
size_t $size,
&compare:(
Pointer[int32] $ap,
Pointer[int32] $bp
--> int32
)
) is native { * }
sub int32-compare (Pointer[int32] $ap, Pointer[int32] $bp --> int32) {
$ap.deref <=> $bp.deref
}
my $ints = CArray[int32].new(1, 6, 5, 3, 4, 2, 7);
$ints[^ $ints.elems].say;
qsort($ints, $ints.elems, nativesizeof(int32), &int32-compare);
$ints[^ $ints.elems].say;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment