-
-
Save Skarsnik/28555eade4bd5a40d036 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
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]; | |
} |
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 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) { * }; |
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
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