Hello,

 

Thanks to the amazing job Lizmat did to implement runtime signatures it can be 
done. You could also probably add some caching of the signatures and the 
functions. I didn’t benchmark. Here the code:

 

use NativeCall;

 

sub pera-int-f(Str $format, *@args) {

 

    state $ptr = cglobal(Str, "printf", Pointer);

 

    my $signature = Signature.new(

        params => (

            Parameter.new(type => Str),

            |(@args.map: { Parameter.new(type => .WHAT) })

        ),

        returns => int32);

 

    my &f = nativecast($signature, $ptr);

 

    f($format, |@args)

}

 

pera-int-f("Pera + Mela = %d + %d %s\n", 25, 12, "cippas");

Reply via email to