Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Embed the perl interpreter in a C# Program

I realize that I have to DllImport the perlembed methods

perl_parse
perl_alloc
perl_free

etc.,

But not sure how to marhsall the function arguments for using it with DLLImport especially with perl_parse method.

I also realize that a related question already exists which is almost there but still the OP has solved by created a C wrapper and then using it in C#.

He says that he was not able to DLLimport PERL_SYS_INIT3.

So my question is how to properly wrap them using only C# and use it?

like image 500
Vivek Bernard Avatar asked Apr 16 '12 14:04

Vivek Bernard


1 Answers

Look at this; I hope it will help (it was called in early version)

I got this from here (perl)

To embed a Perl interpreter in a C# program, add a reference to the COM object "Microsoft Script Control 1.0" and write code like this:

MSScriptControl.ScriptControlClass Interpreter;
Interpreter = new MSScriptControl.ScriptControlClass();
Interpreter.Language = @"PerlScript";
string Program = @"reverse 'abcde'";
string Results = (string)Interpreter.Eval(Program);

The above is equivalent to the following Perl script, which embeds a Perl interpreter within a Perl interpreter:

use Win32::OLE;
my $Interpreter;
$Interpreter = Win32::OLE->new('ScriptControl');
$Interpreter->{Language} = 'PerlScript';
my $Program = "reverse 'abcde'";
my $Results = $Interpreter->Eval($Program);
like image 183
Likurg Avatar answered Oct 13 '22 19:10

Likurg