托管 IronPython 时如何设置动态导入?

发布于 2024-09-10 04:10:19 字数 194 浏览 0 评论 0原文

我正在编写一个 C# 客户端应用程序,旨在为通过脚本进行自定义提供强大支持,并且我选择 IronPython 作为我的目标脚本语言。我想将用户的代码及其其余状态保留在应用程序的数据库中,但我需要用户能够将其脚本拆分为文件和模块。

如何配置 IronPython 引擎,使其使用字符串(带有相应的虚拟路径)作为导入源,而不是在用户文件系统中指定目录?这可能吗?

I'm writing a C# client application which is intended to have strong support for customisation via scripting, and I have chosen IronPython as my target scripting language. I would like to keep the user's code in the application's database with the rest of its state, but I need the user to be able to split their scripts into files and modules.

How can I configure the IronPython engine so that it will use strings (with corresponding virtual paths) as the source for imports, rather than specifying a directory in the user's filesystem? Is this possible?

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

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

发布评论

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

评论(1

绮烟 2024-09-17 04:10:19

您需要子类化 PlatformAdaptationLayer 类并实现“文件系统”调用。然后,IronPython 将转到 PAL 对文件执行 I/O。这还涉及实现返回 PAL 类型的 ScriptHost。一个很好的例子就是 Silverlight 主机,它将文件 I/O 重定向到 XAP 文件。

如果您在 IronPython.CodePlex.com 上浏览 IronPython 源代码,您将在 IronPython_Main\Hosts\Silverlight\Microsoft.Scripting.Silverlight 中找到 Silverlight 主机。

You need to subclass the PlatformAdaptationLayer class and implement the "file system" calls. IronPython will then go to the PAL to do I/O for the files. This also involves implementing a ScriptHost which returns the type for the PAL. A good example of this is the Silverlight host which redirects file I/O to a XAP file.

If you browse the IronPython source on IronPython.CodePlex.com you'll find the Silverlight host in IronPython_Main\Hosts\Silverlight\Microsoft.Scripting.Silverlight.

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