-
Notifications
You must be signed in to change notification settings - Fork 30
/
inline_perl5.pl
executable file
·50 lines (43 loc) · 1.45 KB
/
inline_perl5.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/home/nine/install/rakudo/install/bin/perl6
use v6;
use NativeCall;
class PerlInterpreter is repr('CPointer') {
sub Perl_SvIOK(PerlInterpreter, OpaquePointer)
is native("%*ENV<HOME>/interop/p5helper.so")
returns Int { * }
sub Perl_SvPOK(PerlInterpreter, OpaquePointer)
is native("%*ENV<HOME>/interop/p5helper.so")
returns Int { * }
sub Perl_sv_iv(PerlInterpreter, OpaquePointer)
is native('/usr/lib/perl5/5.18.1/x86_64-linux-thread-multi/CORE/libperl.so')
returns Int { * }
sub sv_to_char_star(PerlInterpreter, OpaquePointer)
is native("%*ENV<HOME>/interop/p5helper.so")
returns Str { * }
sub Perl_eval_pv(PerlInterpreter, Str, Int)
is native('/usr/lib/perl5/5.18.1/x86_64-linux-thread-multi/CORE/libperl.so')
returns OpaquePointer { * }
method run($perl) {
my $res = Perl_eval_pv(self, $perl, 1);
if Perl_SvIOK(self, $res) {
return Perl_sv_iv(self, $res);
}
if Perl_SvPOK(self, $res) {
return sv_to_char_star(self, $res);
}
return $res;
}
}
sub init_perl() is native("%*ENV<HOME>/interop/p5helper.so") returns PerlInterpreter { * }
my $i = init_perl();
say 'Hello world from Perl ' ~ $i.run(q:heredoc/PERL5/);
use Inline Python => <<PYTHON;
def name():
return "Python";
PYTHON
name();
PERL5
say 'Hello world from Perl ' ~ $i.run(q:heredoc/PERL5/);
1 + 1 + 1 + 1 + 1
PERL5
# vim: ft=perl6