Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Arguments are passed to perl 5 methods.

  • Loading branch information...
commit a20956d9993c4ddf39f36054c949088d8b759d59 1 parent 4266b44
@pmurias pmurias authored
Showing with 27 additions and 7 deletions.
  1. +2 −2 examples/perl5.pl
  2. +20 −2 lib/Perl5Interpreter.cs
  3. +5 −3 lib/p5embed.c
View
4 examples/perl5.pl
@@ -11,11 +11,11 @@
package Foo;
sub baz {
my ($self,$arg) = @_;
- print "calling method\n";
+ print "Just another $arg\n";
}
sub new {
bless {},"Foo";
}
PERL5
my $foo = eval(:lang<perl5>,'Foo->new');
-$foo.baz(eval(:lang<perl5>,'"Hello World"'));
+$foo.baz(eval(:lang<perl5>,'"Perl hacker"'));
View
22 lib/Perl5Interpreter.cs
@@ -42,14 +42,32 @@ public class SVVariable : Variable {
}
public class SVany : P6any {
[DllImport("obj/p5embed.so", EntryPoint="p5method_call")]
- public static extern IntPtr MethodCall(string code,IntPtr invocant);
+ public static extern IntPtr MethodCall(
+ string name,
+ IntPtr[] foo,
+ int n
+ );
+
+ public static IntPtr VariableToSV(Variable var) {
+ P6any obj = var.Fetch();
+ if (obj is SVany) {
+ return ((SVany)obj).sv;
+ } else {
+ throw new NieczaException("can't convert argument to p5 type");
+ }
+ }
public IntPtr sv;
public override Frame InvokeMethod(Frame caller, string name,
Variable[] pos, VarHash named) {
- MethodCall(name,sv);
+ IntPtr[] args = new IntPtr[pos.Length];
+ for (int i=0;i<pos.Length;i++) {
+ args[i] = VariableToSV(pos[i]);
+ }
+ MethodCall(name,args,args.Length);
return caller;
}
+
public SVany(IntPtr _sv) {
mo = Kernel.AnyMO;
sv = _sv;
View
8 lib/p5embed.c
@@ -40,16 +40,18 @@ void p5embed_dispose()
PERL_SYS_TERM();
}
-void p5method_call(char* name,SV* invocant) {
+void p5method_call(char* name,int* args,int n) {
dSP;
- SvREFCNT_inc(invocant);
/*ENTER;
SAVETMPS;*/
PUSHMARK(SP);
- XPUSHs(invocant);
+ int i;
+ for (i=0;i<n;i++) {
+ XPUSHs(args[i]);
+ }
PUTBACK;
call_method(name,G_DISCARD);
Please sign in to comment.
Something went wrong with that request. Please try again.