在 C# 应用程序中嵌入 IronScheme

发布于 2024-08-07 13:07:22 字数 4573 浏览 3 评论 0原文

我正在尝试向我的 C# 应用程序添加插件架构。我选择 IronScheme 作为语言,还因为它是基于 DLR 构建的,这应该更容易嵌入。

在 Codeplex Wiki 上,他们有以下示例 。 我稍微改变了它:(

public class PluggerInner
{
    IScriptEngine scheme;

    public PluggerInner()
    {
        InitScheme();
    }

    private void InitScheme()
    {
        var domMgr = ScriptDomainManager.CurrentManager;
        var schemePrv = new IronSchemeLanguageProvider(domMgr);

        scheme = schemePrv.GetEngine();
    }

    public void RunSchemePlugin(string fileName)
    {
        scheme.ExecuteFile(fileName);
    }

    public void RunPlugins()
    {
        foreach (var fl in new DirectoryInfo("../../plugins").GetFiles())
        {
            if (fl.Extension == ".ss")
            {
                RunSchemePlugin(fl.FullName);
            }
        }
    }
}

这基本上是作为 new PluggerInner().RunPlugins() 执行的)

它在目录中找到了我的示例 .ss 文件(是的,我知道我不应该使用 ../..),但会在这一行抛出一个大量错误:

scheme.ExecuteFile(fileName);

我得到的异常是:

IronScheme.Runtime.R6RS.CompoundCondition was unhandled
  Source="IronScheme"
  StackTrace:
       at IronScheme.Runtime.R6RS.Exceptions.Raise(Object obj)
       at IronScheme.Runtime.R6RS.Exceptions.RaiseContinueable(Object obj)
       at IronScheme.Runtime.Builtins.UndefinedError(Object sym)
       at IronScheme.IronSchemeLanguageContext.MissingName(SymbolId name)
       at Microsoft.Scripting.ModuleGlobalWrapper.GetCachedValue()
       at Microsoft.Scripting.ModuleGlobalWrapper.get_CurrentValue()
       at hello.Initialize(CodeContext )
       at Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEvaluate)
       at Microsoft.Scripting.ScriptModule.Execute()
       at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path)
       at ExEdit.PluggerInner.RunSchemePlugin(String fileName) in D:\VSProjects\ExEdit\Infra.cs:line 35
       at ExEdit.PluggerInner.RunPlugins() in D:\VSProjects\ExEdit\Infra.cs:line 44
       at ExEdit.MainForm.MainForm_Load(Object sender, EventArgs e) in D:\VSProjects\ExEdit\MainForm.cs:line 22
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ExEdit.Program.Main() in D:\VSProjects\ExEdit\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

我的示例方案代码:

(define (test) (+ 1 1))

我不知道什么实际上是在谈论异常,因为它没有InnerException。

I'm trying to add a plugin architecture to my C# app. I've chosen IronScheme as the language, and also because it's built on the DLR, which should make it easier to embed.

On the Codeplex Wiki, they have the following example.
I changed it slightly:

public class PluggerInner
{
    IScriptEngine scheme;

    public PluggerInner()
    {
        InitScheme();
    }

    private void InitScheme()
    {
        var domMgr = ScriptDomainManager.CurrentManager;
        var schemePrv = new IronSchemeLanguageProvider(domMgr);

        scheme = schemePrv.GetEngine();
    }

    public void RunSchemePlugin(string fileName)
    {
        scheme.ExecuteFile(fileName);
    }

    public void RunPlugins()
    {
        foreach (var fl in new DirectoryInfo("../../plugins").GetFiles())
        {
            if (fl.Extension == ".ss")
            {
                RunSchemePlugin(fl.FullName);
            }
        }
    }
}

(This is executed basically as new PluggerInner().RunPlugins())

It finds my example .ss file in the directory (yes, I know I shouldn't use ../..), but throws a massive error on this line:

scheme.ExecuteFile(fileName);

The exception I get is:

IronScheme.Runtime.R6RS.CompoundCondition was unhandled
  Source="IronScheme"
  StackTrace:
       at IronScheme.Runtime.R6RS.Exceptions.Raise(Object obj)
       at IronScheme.Runtime.R6RS.Exceptions.RaiseContinueable(Object obj)
       at IronScheme.Runtime.Builtins.UndefinedError(Object sym)
       at IronScheme.IronSchemeLanguageContext.MissingName(SymbolId name)
       at Microsoft.Scripting.ModuleGlobalWrapper.GetCachedValue()
       at Microsoft.Scripting.ModuleGlobalWrapper.get_CurrentValue()
       at hello.Initialize(CodeContext )
       at Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEvaluate)
       at Microsoft.Scripting.ScriptModule.Execute()
       at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path)
       at ExEdit.PluggerInner.RunSchemePlugin(String fileName) in D:\VSProjects\ExEdit\Infra.cs:line 35
       at ExEdit.PluggerInner.RunPlugins() in D:\VSProjects\ExEdit\Infra.cs:line 44
       at ExEdit.MainForm.MainForm_Load(Object sender, EventArgs e) in D:\VSProjects\ExEdit\MainForm.cs:line 22
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ExEdit.Program.Main() in D:\VSProjects\ExEdit\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

My example Scheme code:

(define (test) (+ 1 1))

I have no idea what the exception is actually talking about, as it has no InnerException.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天的雪花 2024-08-14 13:07:22

我认为我没有正确实现 ExecuteFile

最简单的方法就是抓住 load 过程。

还有扩展方法,让生活更轻松。

示例

using IronScheme; // for extension methods
...
Callable load = "load".Eval<Callable>();
...
load.Call("myfile.ss");

我已经更新了异常处理以提供更好的错误消息(我希望如此!)。

I dont think I implemented ExecuteFile correctly.

The easiest is just to grab hold of the load procedure.

Also the extension methods, make life easier.

Example

using IronScheme; // for extension methods
...
Callable load = "load".Eval<Callable>();
...
load.Call("myfile.ss");

I have updated the exception handling to give better error messages (I hope!).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文