Created
March 12, 2019 21:12
-
-
Save salortiz/4cf07738fe247ec89d824731f825b7de to your computer and use it in GitHub Desktop.
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
use v6.c; | |
use NativeCall; | |
# A proof of concept for NativeCall "varargs" calls, | |
my $printf = cglobal(Str,'printf',Pointer); | |
my @sxa := ( | |
(Nil => :(Str --> int32)).Map, # arity 0 | |
(Str => :(Str,Str --> int32), Int => :(Str,Int --> int32)).Map # arity 1 | |
); | |
sub choose-sig(Capture \c) { | |
@sxa[c-1]{c.list[1].^name}; | |
} | |
sub make-callable(Pointer \sym, Capture \c) { | |
my \sig = choose-sig(c); | |
nativecast(sig, sym); | |
} | |
for (\("hi\n"), \("Hello %s\n","perl6"), \("Age: %d\n", 10)) -> \c { | |
my &fun = make-callable($printf, c); | |
fun(|c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment