Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perl5 integers are converted rather than wrapped.
  • Loading branch information
pmurias committed Oct 1, 2011
1 parent d2c05c8 commit 18b719f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/perl5.pl
Expand Up @@ -19,3 +19,5 @@ sub new {
PERL5
my $foo = eval(:lang<perl5>,'Foo->new');
$foo.baz(eval(:lang<perl5>,'"Perl hacker"'));
say eval(:lang<perl5>,"125");

20 changes: 19 additions & 1 deletion lib/Perl5Interpreter.cs
Expand Up @@ -12,7 +12,25 @@ public class Perl5Interpreter : IForeignInterpreter {
[DllImport("obj/p5embed.so", EntryPoint="p5embed_eval")]
public static extern IntPtr EvalPerl5(string code);

[DllImport("obj/p5embed.so", EntryPoint="p5embed_SvIV")]
public static extern int SvIV(IntPtr sv);

[DllImport("obj/p5embed.so", EntryPoint="p5embed_SvIOKp")]
public static extern int SvIOKp(IntPtr sv);

[DllImport("obj/p5embed.so", EntryPoint="p5embed_SvNOKp")]
public static extern int SvNOKp(IntPtr sv);

[DllImport("obj/p5embed.so", EntryPoint="p5embed_SvPOKp")]
public static extern int SvPOKp(IntPtr sv);

public static Variable SVToVariable(IntPtr sv) {
if (SvIOKp(sv) != 0) {
return Builtins.MakeInt(SvIV(sv));
} else {
return new SVVariable(sv);
}
}

public Perl5Interpreter() {
Initialize();
Expand All @@ -21,7 +39,7 @@ public class Perl5Interpreter : IForeignInterpreter {
Dispose();
}
public Variable Eval(string code) {
return new SVVariable(EvalPerl5(code));
return SVToVariable(EvalPerl5(code));
}
}

Expand Down
14 changes: 14 additions & 0 deletions lib/p5embed.c
Expand Up @@ -59,3 +59,17 @@ void p5method_call(char* name,int* args,int n) {
/*FREETMPS;
LEAVE;*/
}

int p5embed_SvIOKp(SV* sv) {
return SvIOKp(sv);
}
int p5embed_SvNOKp(SV* sv) {
return SvNOKp(sv);
}
int p5embed_SvPOKp(SV* sv) {
return SvPOKp(sv);
}

int p5embed_SvIV(SV* sv) {
return SvIV(sv);
}

0 comments on commit 18b719f

Please sign in to comment.