寻找好的嵌入式&托管语言对
我正在寻找两种(一种?)语言。其中之一是主机,能够运行某些“环境”,第二个可以用于编写在此环境中运行的“代理”脚本。
一些细节:
主机应该能够运行多个“代理”(嵌入式语言的线程),理想情况下能够限制每个线程一次执行的指令数量(尽管欢迎更复杂的控制方式)
嵌入式线程应该具有访问权限仅适用于主机显式公开的对象
嵌入式线程应该被隔离。没有共享内存,所有通过主机
嵌入式语言应该相当简单,使用动态类型
托管语言应该相当高级
性能不是主要问题
我正在考虑将 Python 作为嵌入 Lua 的主机,例如 Lunatic Python,或某些 JVM 语言(Scala / Groovy?),但我不确定嵌入式线程真正隔离的可能性(参见 2、3)。所以我正在寻找任何想法、框架、成功的实施等等......
I am searching for two (one?) languages. One of them would be a host, capable running some "environment", and second, which could used to script "agents" acting in this environment.
Some details:
host should be capable to run multiple "agents" (threads of embedded language), ideally capable to limit number of instructions executed by every thread at a time (though more sophisticated ways of control are welcome)
embedded threads should have access only to objects explicitly exposed by host
embedded threads should be isolated. No shared memory, all communication going via host
embedded language should be rather simple, with dynamic typing
hosting language should be rather high-level
performance is not a primary concern
I was thinking of Python being a host embedding Lua, for example Lunatic Python, or some pair of JVM languages (Scala / Groovy ?), but i'am not sure of possibilities of real isolation of embedded threads (see 2, 3). So I am searching for any ideas, frameworks, successfull implementations etc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为您列出的条件并不是非常严格,您将找到符合您的六个要求的大量主机/线程脚本语言对。
因此,我最重要的建议是您选择目标用户最喜欢的语言。
有几种方法可以解决这个问题。如果您决定开始选择宿主语言,那么我认为您有以下选择:
C/C++:如果您的目的是对线程语言有更多的选择自由,那么选择 C 或C++ 主机将为您提供最多的选择,因为大多数解释性脚本语言都是用 C/C++ 编写的,并且具有嵌入到 C/C++ 应用程序中的简单机制。线程语言的选择可以是 Lua、Javascript、Python、Ruby、PHP、Basic、Scheme、Pascal、Lisp 等等。
Java:使用 Java 作为宿主语言,您将拥有少量嵌入友好的脚本语言。 这是一个列表。
.NET:如果您打算在 Windows 上运行而不是其他任何东西,我只会使用它,否则我会避免它。与 Java 一样,您将找到可以嵌入 .NET 应用程序中的解释器列表。
其他:如果您不喜欢 C/C++ 或 Java 作为宿主语言,那么您必须决定您喜欢哪种宿主语言,但无论选择如何,您都会有嵌入式语言的一组非常有限的选项。您建议将 Python 作为可能的宿主语言,我认为这是一个不错的选择。不过,我建议不要使用 Lua 而不是 Python,如果您需要在语言 VM 级别进行调试,那可能会是一场调试噩梦。相反,我可以提供两个建议:(1)也使用Python作为线程语言,那么你在整个系统中就有了一个很好的统一语言; (2) 找到一种具有用 Python 编写的本机解释器的脚本语言(我知道的不多)。除了 Python,您还可以使用 Ruby、PHP 或任何其他主要脚本语言作为主机,但在所有情况下,您对嵌入式语言的选择并不多。
现在,您可以先选择嵌入语言,然后找到可以嵌入该语言的主机语言,而不是寻找宿主语言。您建议Lua作为嵌入式语言,这也是一个非常好的选择。如果您决定使用 Lua,那么我认为 C 或 C++ 应该是您的宿主语言,因为这将为您提供最佳的嵌入体验。
总而言之,我建议使用以下两种方法之一来选择语言对:
(a) 选择一对以宿主语言实现嵌入式语言解释器的语言。示例:Lua 和 C++、Javascript 和 C++、Python 和 C++、Scheme 和 C++、Jython 和 Java、JRuby 和 Java、Rhino 和 Java 等,
或者
(b) 为主机和线程选择相同的高级脚本语言,然后工作在没有嵌入式脚本的统一平台上。示例:Python 和 Python、Lua 和 Lua、Ruby 和 Ruby 等。
祝您搜索顺利!
I think the conditions that you have listed aren't very restrictive, you are going to find a large list of pairs of host/thread scripting languages that fall within your six requirements.
So my most important recommendation is that you choose the languages that the intended users will like the most.
There are a couple of ways to approach this. If you decide to start picking a host language, then I think you have the following options:
C/C++: If your intention is to have more freedom of choice for the thread language, then having a C or C++ host will give you the most options, since most interpreted scripting languages are written in C/C++ and have easy mechanisms for embedding into C/C++ applications. Choices for thread languages could be Lua, Javascript, Python, Ruby, PHP, Basic, Scheme, Pascal, Lisp, and many many more.
Java: With Java as a host language you have a short number of scripting languages that are embed friendly. Here is a list.
.NET: I would only go with this if you intend to run on Windows and nothing else, if not I would avoid it. Like Java, you'll find a list of interpreters that can be embedded in a .NET application.
Something else: If you don't like C/C++ or Java as a host language, then you'll have to decide what kind of host language you like, but no matter the choice, you will have a very limited set of options for an embedded language. You suggested Python as a possible host language, which I think is a decent choice. I would advise against using Lua over Python though, that could be a debugging nightmare should you ever need to debug at the language VM level. Instead, I can offer two suggestions: (1) also use Python for the thread language, then you have a nice uniform language across the entire system; (2) find a scripting language that has a native interpreter written in Python (there aren't many that I know of). Instead of Python, you can go with Ruby, PHP, or any other major scripting language for the host, but in all cases you'll have not many options for the embedded language.
Now, instead of looking for a host language, you could pick the embedded language first, then find a host language that can embed that language. You suggested Lua as an embedded language, which is also a very good option. If you are set on using Lua, then I think C or C++ should be your host language, as that will give you the best embedding experience.
To summarize, I recommend one of two following approaches to choosing your pair of languages:
(a) pick a pair of languages where the embedded language interpreter is implemented in the host language. Examples: Lua and C++, Javascript and C++, Python and C++, Scheme and C++, Jython and Java, JRuby and Java, Rhino and Java, etc.
or
(b) pick the same high level scripting language for host and threads, and work on an unified platform without embedded scripting. Examples: Python and Python, Lua and Lua, Ruby and Ruby, etc.
Good luck with your search!
您还可以使用 Common Lisp,特别是通过其 SBCL 实现。
You could also use Common Lisp in particular thru its SBCL implementation.
使用 javascript/v8 作为嵌入式语言,使用 c++ 作为宿主语言可能是一个很好的解决方案。请参阅此内容了解如何嵌入。
V8 提供上下文,每个上下文都有自己的安全上下文。这些允许您为不同的客户端创建多个单独的线程,每个线程都位于自己的沙箱中。
另一种选择是 java/javascript(rhino),它也允许嵌入。在 java 中限制对其他对象的访问会更困难(您必须使用安全管理器),但您可以限制允许脚本执行的时间,请参阅 javadocs 此处。
Using javascript/v8 as the embedded language, and c++ as the host language might be a good solution. See this for how to embed.
V8 provides Contexts, each of which has its own Security Context. These allow you to create multiple separate threads for different clients, each of which is in their own sandbox.
Another alternative is java/javascript(rhino) which also allows embedding. Limiting access to other objects will be harder in java (you have to use a security manager), but you can limit the time a script is allowed to take, see an example in the javadocs here.
我知道这个问题已经有几年了,但我建议使用 ObjectScript 语言。
ObjectScript,简称OS,是一种新的编程语言。它是免费的、跨平台的、轻量级的、可嵌入的和开源的。它结合了多种语言的优点,包括:JavaScript、Lua、Ruby、Python 和 PHP。 OS 具有 Javascript 语法、lua 的“多重结果”功能、Ruby 的语法 shugar 以及 PHP 和 Ruby 的魔术方法 - 甚至更多!
I know this question is a couple of years old now, but I'd recommend ObjectScript language.
ObjectScript, OS for short, is a new programming language. It's free, cross-platform, lightweight, embeddable and open-source. It combines the benefits of multiple languages, including: JavaScript, Lua, Ruby, Python and PHP. OS features the syntax of Javascripts, the "multiple results" feature from lua, syntactic shugar from Ruby as well as magic methods from PHP and Ruby - and even more!
一个很好的例子是 SnapScript 它可以在任何 Java 兼容环境中运行。除了标准 JRE 之外,它还可以在 Android(Dalvik 和 ART)上运行,无需任何修改。
IDE 实际上管理一个用于热执行的代理池。
A good example here is SnapScript it can be run on any Java compatible environment. In addition to the standard JRE it can also be run on Android (Dalvik and ART) without any modifications.
The IDE actually manages an agent pool for hot execution.