Skip to content

Instantly share code, notes, and snippets.

@niner
Created August 7, 2017 09:22
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 niner/0de8371393bff876decdf47fdacb5e6b to your computer and use it in GitHub Desktop.
Save niner/0de8371393bff876decdf47fdacb5e6b to your computer and use it in GitHub Desktop.
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