Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 0faf460149
Fetching contributors…

Cannot retrieve contributors at this time

77 lines (64 sloc) 2.01 KB
using Niecza;
using System.Runtime.InteropServices;
using System;
public class Perl5Interpreter : IForeignInterpreter {
[DllImport("obj/", EntryPoint="p5embed_initialize")]
public static extern void Initialize();
[DllImport("obj/", EntryPoint="p5embed_dispose")]
public static extern void Dispose();
[DllImport("obj/", EntryPoint="p5embed_eval")]
public static extern IntPtr EvalPerl5(string code);
public Perl5Interpreter() {
~Perl5Interpreter() {
public Variable Eval(string code) {
return new SVVariable(EvalPerl5(code));
public class SVVariable : Variable {
public IntPtr sv;
public SVVariable(IntPtr _sv) {
sv = _sv;
public override P6any Fetch() {
return new SVany(sv);
public override void Store(P6any v) {
public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
public class SVany : P6any {
[DllImport("obj/", EntryPoint="p5method_call")]
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) {
IntPtr[] args = new IntPtr[pos.Length];
for (int i=0;i<pos.Length;i++) {
args[i] = VariableToSV(pos[i]);
return caller;
public SVany(IntPtr _sv) {
mo = Kernel.AnyMO;
sv = _sv;
Jump to Line
Something went wrong with that request. Please try again.