Created
August 7, 2017 09:22
-
-
Save niner/0de8371393bff876decdf47fdacb5e6b 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
diff --git a/lib/NativeCall.pm6 b/lib/NativeCall.pm6 | |
index 1dc55e778..bbdd1973f 100644 | |
--- a/lib/NativeCall.pm6 | |
+++ b/lib/NativeCall.pm6 | |
@@ -323,11 +323,27 @@ my role Native[Routine $r, $libname where Str|Callable|List|IO::Path|Distributio | |
$!rettype := nqp::decont(map_return_type($r.returns)); | |
$!arity = $r.signature.arity; | |
$!setup = 1; | |
+ my $block := -> |args { | |
+ my Mu $args := nqp::getattr(nqp::decont(args), Capture, '@!list'); | |
+ if nqp::elems($args) != $!arity { | |
+ X::TypeCheck::Argument.new( | |
+ :objname($.name), | |
+ :arguments(args.list.map(*.^name)) | |
+ :signature(try $r.signature.gist), | |
+ ).throw | |
+ } | |
+ nqp::nativecall($!rettype, self, $args); | |
+ }; | |
+ nqp::bindattr(self, Code, '$!do', nqp::getattr($block, Code, '$!do')); | |
+ nqp::setinvokespec(self, | |
+ Code.HOW.invocation_attr_class(Code), | |
+ Code.HOW.invocation_attr_name(Code), | |
+ nqp::null()); | |
} | |
} | |
method CALL-ME(|args) { | |
- self!setup unless $!setup; | |
+ self!setup(); | |
my Mu $args := nqp::getattr(nqp::decont(args), Capture, '@!list'); | |
if nqp::elems($args) != $!arity { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment