Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Passing no library name will resolve to the main program's symbol table

  • Loading branch information...
commit 37c4b6112476db86d977f874c1d972de0a81c120 1 parent 5e76b5e
@cxreg cxreg authored
Showing with 11 additions and 8 deletions.
  1. +1 −1  examples/unix-fork.p6
  2. +10 −7 lib/NativeCall.pm6
View
2  examples/unix-fork.p6
@@ -1,7 +1,7 @@
use v6;
use NativeCall;
-sub fork() returns Int is native('libz') { ... }
+sub fork() returns Int is native() { ... }
my $children = 15;
for 1 .. $children -> $child {
View
17 lib/NativeCall.pm6
@@ -89,22 +89,25 @@ our sub make-mapper(Mu $type) {
}
}
-our multi trait_mod:<is>(Routine $r, $libname, :$native!) {
+our multi trait_mod:<is>(Routine $r, $libname?, :$native!) {
my $entry-point = $r.name();
my $call-sig = perl6-sig-to-backend-sig($r);
my $return-mapper = make-mapper($r.returns);
- my $lib = pir::loadlib__Ps($libname);
- # $*ERR.say: "routine $r.name() signature $call-sig";
- unless $lib {
- die "The native library '$libname' required for '$entry-point' could not be located";
+ my $lib;
+ if $libname ne '' {
+ $lib = pir::loadlib__Ps($libname);
+ # $*ERR.say: "routine $r.name() signature $call-sig";
+ unless $lib {
+ die "The native library '$libname' required for '$entry-point' could not be located";
+ }
}
pir::setattribute__vPsP($r, '$!do', -> |$c {
$return-mapper(
pir::descalarref__PP( (pir::dlfunc__PPss(
- pir::descalarref__PP($lib),
+ ($lib ?? pir::descalarref__PP($lib) !! pir::null__P()),
$entry-point,
$call-sig
- ) // die("Could not locate symbol '$entry-point' in native library '$libname'")
+ ) // die("Could not locate symbol '$entry-point' in native library '{$libname || q<(resident)>}'")
).(|$c) )
)
});
Please sign in to comment.
Something went wrong with that request. Please try again.