Created
May 5, 2019 11:43
-
-
Save taboege/2e95ce969d26d00342669723c1a11dd1 to your computer and use it in GitHub Desktop.
NativeCall callback signature syntax?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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