【问题标题】:How to Embed the perl interpreter in a C# Program如何在 C# 程序中嵌入 perl 解释器
【发布时间】:2012-04-16 14:29:05
【问题描述】:

我意识到我必须DllImport perlembed 方法

perl_parse
perl_alloc
perl_free

等等,

但不确定如何将函数参数与DLLImport 一起使用,尤其是perl_parse 方法。

我还意识到related question 已经存在,它几乎就在那里,但 OP 仍然通过创建 C 包装器然后在 C# 中使用它来解决。

他说他无法 DLLimport PERL_SYS_INIT3。

所以我的问题是如何仅使用 C# 正确包装它们并使用它?

【问题讨论】:

标签: c# perl interop dllimport


【解决方案1】:

看看这个;我希望它会有所帮助(它在早期版本中被调用)

我从这里得到这个 (perl)

要在 C# 程序中嵌入 Perl 解释器,请添加对 COM 对象“Microsoft Script Control 1.0”的引用并编写如下代码:

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

上面等价于下面的 Perl 脚本,它在 Perl 解释器中嵌入了一个 Perl 解释器:

use Win32::OLE;
my $Interpreter;
$Interpreter = Win32::OLE->new('ScriptControl');
$Interpreter->{Language} = 'PerlScript';
my $Program = "reverse 'abcde'";
my $Results = $Interpreter->Eval($Program);

【讨论】:

  • 只有在您安装了带有 PerlScript 功能的 Active State Perl 时才有效。如果你有不同的 Perl(例如你从源代码编译 Perl)你没有在系统中安装 PerlScript。
猜你喜欢
  • 1970-01-01
  • 2011-01-04
  • 2010-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多