Skip to content

Instantly share code, notes, and snippets.

@Skarsnik

Skarsnik/NC.pm6 Secret

Created February 15, 2016 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skarsnik/28555eade4bd5a40d036 to your computer and use it in GitHub Desktop.
Save Skarsnik/28555eade4bd5a40d036 to your computer and use it in GitHub Desktop.
multi trait_mod:<is>(Routine $r, :$native! where Str|Callable|List) is export(:DEFAULT, :traits) {
check_routine_sanity($r);
say "STR/List/Callable";
say $native.WHAT;
$r does Native[$r, $native === True ?? Str !! $native];
}
multi trait_mod:<is>(Routine $r, :$native!) is export(:DEFAULT, :traits) {
say "HELLO";
say $native.WHAT;
}
multi trait_mod:<is>(Routine $r, NC-Library-Handle :$native!) is export(:DEFAULT, :traits) {
say "Get a libhandle";
check_routine_sanity($r);
$r does Native[$r, $native];
}
use NativeCall;
# First arg is just a 'key' name, second is basename of the lib. You will need etheir :version or :no-version
# ENV argument is optionnal. the corresponding ENV variable will be used instead of the rest if defined.
# The value returned is a NC-Library-Handle object (it's a 'hidden' role)
my \GUMBO_LIB = register-native-library('Gumbo', 'gumbo', :version(v1), :ENV<PERL6_LIBGUMBO>);
sub foo is native { * };
sub bar is native('hello') { * };
sub piko is native(GUMBO_LIB) { * };
skarsnik@testperl6:~/devel/rakudo$ ./install/bin/perl6 -I lib testnc.p6
HELLO
(Bool)
STR/List/Callable
(Str)
===SORRY!=== Error while compiling /home/skarsnik/devel/rakudo/testnc.p6
Can't use unknown trait 'is native' in a sub declaration.
at /home/skarsnik/devel/rakudo/testnc.p6:12
expecting any of:
rw raw hidden-from-backtrace hidden-from-USAGE
pure default DEPRECATED inlinable nodal
prec equiv tighter looser assoc leading_docs trailing_docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment