Vivek Bernard
Vivek Bernard

Reputation: 2073

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?

Upvotes: 16

Views: 2300

Answers (1)

Likurg
Likurg

Reputation: 2760

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);

Upvotes: 2

Related Questions