Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some initial experimental code that shows how we can call a Win32…

… API. It's hardcoded for only that signature for now; next is to map Perl 6 signatures to C signatures.
  • Loading branch information...
commit bd56459f9bb1a9f99d4172e0dc557cd8d0a04f19 1 parent 5d75868
@jnthn authored
Showing with 22 additions and 0 deletions.
  1. +7 −0 examples/win32-api-call.p6
  2. +15 −0 lib/NativeCall.pm
View
7 examples/win32-api-call.p6
@@ -0,0 +1,7 @@
+use NativeCall;
+
+sub MessageBoxA(Int $phWnd, Str $message, Str $caption, Int $flags)
+ is native('user32')
+ { ... }
+
+MessageBoxA(0, "We can haz NCI?", "oh lol", 64);
View
15 lib/NativeCall.pm
@@ -0,0 +1,15 @@
+our sub perl6-sig-to-backend-sig(Signature $siggy) {
+ "llttl"
+}
+
+our multi trait_mod:<is>(Routine $r, $libname, :$native!) {
+ my $entry-point = $r.name();
+ my $call-sig = perl6-sig-to-backend-sig($r.signature());
+ pir::setattribute__vPsP($r, '$!do', -> |$c {
+ (pir::dlfunc__PPss(
+ pir::loadlib__Ps($libname),
+ $entry-point,
+ $call-sig
+ )).(|$c)
+ });
+}
Please sign in to comment.
Something went wrong with that request. Please try again.