Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Convert perl 5 string in an extremely naive fashion ignoring utf and …
…null bytes.
  • Loading branch information
pmurias committed Oct 1, 2011
1 parent f20f832 commit c43c708
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/perl5.pl
Expand Up @@ -11,14 +11,16 @@
package Foo;
sub baz {
my ($self,$arg) = @_;
print "Just another $arg\n";
my $who = $$arg;
print "Just another $who\n";
}
sub new {
bless {},"Foo";
}
PERL5
my $foo = eval(:lang<perl5>,'Foo->new');
$foo.baz(eval(:lang<perl5>,'"Perl hacker"'));
$foo.baz(eval(:lang<perl5>,'\"Perl hacker"'));
say eval(:lang<perl5>,"125");
say eval(:lang<perl5>,"13.5");
say eval(:lang<perl5>,"'Hello there'");

6 changes: 6 additions & 0 deletions lib/Perl5Interpreter.cs
Expand Up @@ -15,6 +15,9 @@ public class Perl5Interpreter : IForeignInterpreter {
[DllImport("obj/p5embed.so", EntryPoint="p5embed_SvIV")]
public static extern int SvIV(IntPtr sv);

[DllImport("obj/p5embed.so", EntryPoint="p5embed_SvPV_nolen")]
public static extern string SvPV_nolen(IntPtr sv);

[DllImport("obj/p5embed.so", EntryPoint="p5embed_SvNV")]
public static extern double SvNV(IntPtr sv);

Expand All @@ -32,6 +35,9 @@ public class Perl5Interpreter : IForeignInterpreter {
return Builtins.MakeInt(SvIV(sv));
} else if (SvNOKp(sv) != 0) {
return Builtins.MakeFloat(SvNV(sv));
} else if (SvPOKp(sv) != 0) {
string s = SvPV_nolen(sv);
return Kernel.BoxAnyMO(s, Kernel.StrMO);
} else {
return new SVVariable(sv);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/p5embed.c
Expand Up @@ -76,3 +76,6 @@ int p5embed_SvIV(SV* sv) {
double p5embed_SvNV(SV* sv) {
return SvNV(sv);
}
char* p5embed_SvPV_nolen(SV* sv) {
return SvPV_nolen(sv);
}

0 comments on commit c43c708

Please sign in to comment.