Skip to content

Commit

Permalink
Support floats passed from P5 to P6
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Sep 17, 2014
1 parent 0513cdd commit d22f0eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Inline/Perl5.pm6
Expand Up @@ -64,6 +64,9 @@ sub p5_init_perl()
sub p5_SvIOK(Perl5Interpreter, OpaquePointer)
returns Int { ... }
native(&p5_SvIOK);
sub p5_SvNOK(Perl5Interpreter, OpaquePointer)
returns Int { ... }
native(&p5_SvNOK);
sub p5_SvPOK(Perl5Interpreter, OpaquePointer)
returns Int { ... }
native(&p5_SvPOK);
Expand Down Expand Up @@ -157,6 +160,9 @@ sub p5_destruct_perl(Perl5Interpreter)
sub p5_sv_iv(Perl5Interpreter, OpaquePointer)
returns Int { ... }
native(&p5_sv_iv);
sub p5_sv_nv(Perl5Interpreter, OpaquePointer)
returns num64 { ... }
native(&p5_sv_nv);
sub p5_is_object(Perl5Interpreter, OpaquePointer)
returns Int { ... }
native(&p5_is_object);
Expand Down Expand Up @@ -293,6 +299,9 @@ method p5_to_p6(OpaquePointer $value) {
p5_sv_refcnt_inc($!p5, $value);
return Perl5Callable.new(perl5 => self, ptr => $value);
}
elsif p5_SvNOK($!p5, $value) {
return p5_sv_nv($!p5, $value);
}
elsif p5_SvIOK($!p5, $value) {
return p5_sv_iv($!p5, $value);
}
Expand Down
8 changes: 8 additions & 0 deletions p5helper.c
Expand Up @@ -48,6 +48,10 @@ int p5_SvIOK(PerlInterpreter *my_perl, SV* sv) {
return SvIOK(sv);
}

int p5_SvNOK(PerlInterpreter *my_perl, SV* sv) {
return SvNOK(sv);
}

int p5_SvPOK(PerlInterpreter *my_perl, SV* sv) {
return SvPOK(sv);
}
Expand All @@ -56,6 +60,10 @@ int p5_sv_iv(PerlInterpreter *my_perl, SV* sv) {
return SvIV(sv);
}

double p5_sv_nv(PerlInterpreter *my_perl, SV* sv) {
return SvNV(sv);
}

int p5_is_object(PerlInterpreter *my_perl, SV* sv) {
return sv_isobject(sv);
}
Expand Down
1 change: 1 addition & 0 deletions t/p5_to_p6.t
Expand Up @@ -7,6 +7,7 @@ use Inline::Perl5;
my $p5 = Inline::Perl5.new();

is $p5.run('5'), 5;
is $p5.run('5.5'), 5.5;
is $p5.run('"Perl 5"'), 'Perl 5';
is_deeply $p5.run('[1, 2]'), [1, 2];
is_deeply $p5.run('[1, [2, 3]]'), [1, [2, 3]];
Expand Down

0 comments on commit d22f0eb

Please sign in to comment.