Browse files

Clean up pull request. As discussed on #perl6.

Renames is named trait to is symbol, use defined-or instead of boolean-or when
checking return value of native_symbol (moritz++). Add basic test to make sure
it works.
  • Loading branch information...
1 parent 4af0a9a commit bc26b5e378b1401015ea893af924fdcfea7ad39d @arnsholt arnsholt committed Aug 7, 2012
Showing with 17 additions and 9 deletions.
  1. +3 −3 README.markdown
  2. +5 −5 lib/NativeCall.pm6
  3. +5 −0 t/01-argless.c
  4. +4 −1 t/01-argless.t
View
6 README.markdown
@@ -39,16 +39,16 @@ used in the library you're loading. Maybe the name is long or has different cas
or is otherwise cumbersome within the context of the module you are trying to
create.
-Zavolaj provides a "named" trait for you to specify the name of the native
+Zavolaj provides a "symbol" trait for you to specify the name of the native
routine in your library that may be different from your Perl subroutine name.
module Foo;
use NativeCall;
- our sub Init() is native('libfoo') is named('FOO_INIT') { * }
+ our sub Init() is native('libfoo') is symbol('FOO_INIT') { * }
Inside of "libfoo" there is a routine called "FOO\_INIT" but, since we're
creating a module called Foo and we'd rather call the routine as Foo::Init,
-we use the "named" trait to specify the name of the symbol in "libfoo"
+we use the "symbol" trait to specify the name of the symbol in "libfoo"
and call the subroutine whatever we want ("Init" in this case).
## Passing and Returning Values
View
10 lib/NativeCall.pm6
@@ -97,8 +97,8 @@ multi sub map_return_type($type) {
$type
}
-my role Named[Str $name] {
- method native_name() { $name }
+my role NativeCallSymbol[Str $name] {
+ method native_symbol() { $name }
}
# This role is mixed in to any routine that is marked as being a
@@ -117,7 +117,7 @@ my role Native[Routine $r, Str $libname] {
"$libname$*VM<config><load_ext>";
nqp::buildnativecall(self,
nqp::unbox_s($realname), # library name
- nqp::unbox_s(self.?native_name || $r.name), # symbol to call
+ nqp::unbox_s(self.?native_symbol // $r.name), # symbol to call
nqp::unbox_s($conv), # calling convention
$arg_info,
return_hash_for($r.signature));
@@ -226,8 +226,8 @@ my class CArray is export is repr('CArray') {
}
}
-multi trait_mod:<is>(Routine $r, :$named!) is export {
- $r does Named[$named];
+multi trait_mod:<is>(Routine $r, :$symbol!) is export {
+ $r does NativeCallSymbol[$symbol];
}
# Specifies that the routine is actually a native call, into the
View
5 t/01-argless.c
@@ -11,3 +11,8 @@ DLLEXPORT void Argless()
printf("ok 1 - Called argless function\n");
fflush(stdout);
}
+
+DLLEXPORT void long_and_complicated_name()
+{
+ printf("ok 3 - called long_and_complicated_name");
+}
View
5 t/01-argless.t
@@ -2,13 +2,16 @@ use lib '.';
use t::CompileTestLib;
use NativeCall;
-say "1..2";
+say "1..3";
compile_test_lib('01-argless');
sub Argless() is native('./01-argless') { * }
+sub short() is native('./01-argless') is symbol('long_and_complicated_name') { *}
# This emits the "ok 1"
Argless();
say("ok 2 - survived the call");
+
+short();

0 comments on commit bc26b5e

Please sign in to comment.