Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support passing floats from Python to Perl
  • Loading branch information
niner committed Oct 14, 2014
1 parent da0ed60 commit 95b6488
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/Inline/Python.pm6
Expand Up @@ -28,6 +28,9 @@ sub py_eval(Str, Int)
sub py_int_check(OpaquePointer)
returns int32 { ... }
native(&py_int_check);
sub py_float_check(OpaquePointer)
returns int32 { ... }
native(&py_float_check);
sub py_unicode_check(OpaquePointer)
returns int32 { ... }
native(&py_unicode_check);
Expand All @@ -46,6 +49,9 @@ sub py_int_as_long(OpaquePointer)
sub py_int_to_py(Int)
returns OpaquePointer { ... }
native(&py_int_to_py);
sub py_float_as_double(OpaquePointer)
returns num64 { ... }
native(&py_float_as_double);
sub py_float_to_py(num64)
returns OpaquePointer { ... }
native(&py_float_to_py);
Expand Down Expand Up @@ -107,6 +113,9 @@ method py_to_p6(OpaquePointer $value) {
if py_int_check($value) {
return py_int_as_long($value);
}
elsif py_float_check($value) {
return py_float_as_double($value);
}
elsif py_unicode_check($value) {
return py_unicode_to_char_star($value);
}
Expand Down
8 changes: 8 additions & 0 deletions pyhelper.c
Expand Up @@ -44,6 +44,10 @@ int py_int_check(PyObject *obj) {
return PyInt_Check(obj);
}

int py_float_check(PyObject *obj) {
return PyFloat_Check(obj);
}

int py_unicode_check(PyObject *obj) {
return PyUnicode_Check(obj);
}
Expand All @@ -64,6 +68,10 @@ long py_int_as_long(PyObject *obj) {
return PyInt_AsLong(obj);
}

double py_float_as_double(PyObject *obj) {
return PyFloat_AsDouble(obj);
}

PyObject *py_int_to_py(long num) {
return PyInt_FromLong(num);
}
Expand Down
1 change: 0 additions & 1 deletion t/py_to_p6.t
Expand Up @@ -7,7 +7,6 @@ use Inline::Python;
my $py = Inline::Python.new();

is $py.run('5', :eval), 5;
todo 'NYI';
is $py.run('5.5', :eval), 5.5;
is $py.run('u"Python"', :eval), 'Python';
is_deeply $py.run('[1, 2]', :eval), [1, 2];
Expand Down

0 comments on commit 95b6488

Please sign in to comment.