Skip to content

Commit 22b5fc9

Browse files
awwaiidniner
authored andcommitted
Teach EVAL how to :from<Python>
Plus a bonus .gitignore
1 parent 5c52d88 commit 22b5fc9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.prove
22
lib/Inline/pyhelper.so
33
Makefile
4+
lib/.precomp
5+
resources

lib/Inline/Python.pm6

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ role PythonParent[$package, $class] {
519519
);
520520
}
521521

522+
method default_python {
523+
$default_python //= self.new;
524+
}
525+
522526
BEGIN {
523527
PythonObject.^add_fallback(-> $, $ { True },
524528
method ($name) {
@@ -537,3 +541,8 @@ BEGIN {
537541
}
538542
PythonObject.^compose;
539543
}
544+
545+
multi sub EVAL(Cool $code, Str :$lang where { ($lang // '') eq 'Python' }, PseudoStash :$context) is export {
546+
state $py = ::("Inline::Python").default_python;
547+
$py.run($code);
548+
}

t/eval.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
use v6;
44
use Inline::Python;
55

6-
say '1..1';
6+
say '1..2';
7+
8+
EVAL 'print "ok 1 - EVAL eval\n"', :from<Python>;
79

810
my $py = Inline::Python.new();
911

1012
$py.run('
11-
print "ok 1 - basic eval\n";
13+
print "ok 2 - direct eval\n";
1214
', :file);
1315

1416
# vim: ft=perl6

0 commit comments

Comments
 (0)