fsi.exe 程序集:有人知道如何嵌入它吗?
长期读者,第一个问题。 fsi.exe 是一个 .NET 可执行文件,因此包含自己的程序集,其中包含所有美味的方法以及 fsi 用于执行 F# 脚本的内容。
查看 .NET Reflector 中的程序集(选择您的类,但 Shell 是最好的例子)会发现一堆垃圾 * 名称,看起来像装饰过的 C++ 函数(例如,来自 Dependency Walker)。顺便说一句,有点离题的是,F# 程序集的编译方式大致相同,但有很多垃圾*名称,这让我认为 fsi.exe 是用 F# 编写的,也许是为了证明可用性?
无论如何,这是我的问题:是否有人深入研究 fsi.exe 并弄清楚如何将其嵌入到 .NET 应用程序中?因为我想使用 F# 作为脚本语言,但程序编译为(令人惊讶的)程序,并且脚本必须由 fsi.exe 执行,这在我的域中是不可接受的(我需要一个持久的 VM)。我不希望有关于使用 fsi.exe 的操作指南,但我很好奇是否有人使用过它,如果是的话,您对它的工作原理有什么发现?
感谢您抽出时间。
* 一眼看上去就是垃圾。显然,它们以这种特定方式格式化是出于幕后的特定原因。
Long time reader, very first question. fsi.exe is a .NET executable and therefore contains its own assembly complete with all the yummy methods and whatnot fsi uses to execute F# scripts.
Looking at the assembly in .NET Reflector (pick your class, but Shell is the best example) reveals a bunch of garbage* names that look like decorated C++ functions (say, from Dependency Walker). Incidentally and slightly beside the point, F# assemblies compile in much the same way, with lots of garbage* names, which leads me to think fsi.exe was written in F#, perhaps as a proof-of-usability?
Anyway, here's my question: has anyone delved into fsi.exe and figured out how to embed it into a .NET application? Because I'd like to use F# as a scripting language, but programs compile to (surprise) programs, and scripts must be executed by fsi.exe, which is unacceptable in my domain (I need a persistent VM). I don't expect a how-to guide on using fsi.exe, but I'm curious to know if anyone has played with it and, if so, what have you discovered about how it works?
Thanks for your time.
* Garbage at a casual glance. Obviously they are formatted this particular way for a particular reason that is beneath the hood.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,
fsi.exe
不会公开任何可用于将其嵌入到应用程序中的 API(例如,实现脚本编写)。我认为本质上有两个选择:如果您想直接使用现有的
fsi.exe
,唯一的方法是使用.NETProcess
类启动它并进行通信以某种方式与它。这应该是可行的 - 您可以使用标准输入向进程发送命令。要读回输出,您可以使用标准输出,但这只能提供有限的信息。可能可以使用 .NET 远程处理在fsi.exe
和您的应用程序之间进行通信(例如,在 FSI 的脚本上下文中加载的对象将通过远程处理向您的应用程序发送信息)。另一种替代方法是使用 F# 的开源版本并修改
fsi.exe< /code> 将您需要的所有信息公开为 API。这需要更多的努力才能理解 fsi.exe 的工作原理,但它应该是可行的。您可能不需要那么多添加 - FSI 维护的状态包含全局变量之类的东西。
关于许可证 - 您可能无法使用随 Visual Studio 分发的
fsi.exe
。我不确定 CTP 版本附带的fsi.exe
。从源代码编译它(可在此处获得)绝对没问题(因为它有开源版本)。As far as I know,
fsi.exe
doesn't expose any API that you could use to embed it in your application (e.g. to implement scripting). I think there are essentially two options:If you want to use existing
fsi.exe
directly, the only way is to start it using .NETProcess
class and communicate with it somehow. This should be doable - you can send commands to the process using standard input. To read output back, you can use standard output, but this gives you only limited information. It probably would be possible to use .NET Remoting to communicate betweenfsi.exe
and your application (e.g. your objects loaded in script context in FSI would send information to your application via Remoting).Another alternative is to use the open-source release of F# and modify
fsi.exe
to expose all information you need as an API. This requires more effort in order to understand howfsi.exe
works, but it should be doable. You probably don't need that many additions - the state maintained by FSI contains things like global variables.Regarding the license - you probably cannot use
fsi.exe
distributed with Visual Studio. I'm not sure aboutfsi.exe
that comes with the CTP release. Compiling it from source (available here) will be definitely fine (because it has open-source release).这里有一些工作代码:
http://www.codeproject.com/Articles /241577/嵌入式脚本使用-Fsharp
There's some working code here:
http://www.codeproject.com/Articles/241577/Embedded-scripting-using-Fsharp