Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support passing Nums from Perl to Python
  • Loading branch information
niner committed Oct 14, 2014
1 parent 95b6488 commit 8849d3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/Inline/Python.pm6
Expand Up @@ -143,6 +143,10 @@ multi method p6_to_py(Int:D $value) returns OpaquePointer {
py_int_to_py($value);
}

multi method p6_to_py(Num:D $value) returns OpaquePointer {
py_float_to_py($value);
}

multi method p6_to_py(Rat:D $value) returns OpaquePointer {
py_float_to_py($value.Num);
}
Expand Down
8 changes: 4 additions & 4 deletions t/p6_to_py.t
Expand Up @@ -4,7 +4,7 @@ use v6;
use Test;
use Inline::Python;

plan 6;
plan 8;

my $py = Inline::Python.new();
$py.run(q[
Expand All @@ -14,8 +14,8 @@ def identity(a):

class Foo {
}
# , 2.4.Num, [1, 2], { a => 1, b => 2}, Any, Foo.new
for ('abcö', Buf.new('äbc'.encode('latin-1')), 24) -> $obj {
# , [1, 2], { a => 1, b => 2}, Any, Foo.new
for ('abcö', Buf.new('äbc'.encode('latin-1')), 24, 2.4.Num) -> $obj {
is_deeply $py.call('__main__', 'identity', $obj), $obj, "Can round-trip " ~ $obj.^name;
}

Expand All @@ -41,6 +41,6 @@ def is_two_point_five(a):
/);

ok($py.call('__main__', 'is_two_point_five', 2.5));
#ok($py.call('__main__', 'is_two_point_five', Num.new(2.5)));
ok($py.call('__main__', 'is_two_point_five', Num.new(2.5)));

# vim: ft=perl6

0 comments on commit 8849d3f

Please sign in to comment.