简体   繁体   English

为 C++ 选择嵌入式脚本语言

[英]Choosing embedded scripting language for C++

I want to choose an embedded scripting language that i will use on C++.我想选择一种嵌入式脚本语言,我将在 C++ 上使用它。 It should connect a database such as Oracle.它应该连接一个数据库,例如 Oracle。 My host application is a server application.我的主机应用程序是一个服务器应用程序。 That will pass raw data to script.这会将原始数据传递给脚本。 The script will parse and do some specific logics.该脚本将解析并执行一些特定的逻辑。 Also updates database.还更新数据库。 Then script will returns raw data as result.然后脚本将返回原始数据作为结果。 Can you help me to choose it?可以帮我选吗? Thanx谢谢

Lua is intended to be an embedded language and has a simple API . Lua旨在成为一种嵌入式语言,并具有简单的 API Python and Ruby are much more general purpose and are (for embedding at least) significantly more complicated. Python 和 Ruby 更通用,并且(至少对于嵌入)要复杂得多。 This alone would lead me to using Lua.仅此一项就可以让我使用 Lua。

Lua is already mentioned and using luabind will give you a more c++ style interface. Lua已经被提及,使用luabind会给你一个更 c++ 风格的界面。
You could also take a look at chaiscript .你也可以看看chaiscript It was more designed to fit into c++.它的设计更适合 c++。

Save this as test.c:将此另存为 test.c:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}

Run this command (if you have Python 2.7 installed):运行此命令(如果您安装了 Python 2.7):

gcc test.c -o test -I/usr/include/python2.7 -lpython2.7 gcc test.c -o test -I/usr/include/python2.7 -lpython2.7

Python has now been embedded. Python 现已嵌入。 This took me under a minute, so I'm having a hard time understanding the claims of the "effort needed to embed it".这花了我不到一分钟的时间,所以我很难理解“嵌入它所需的努力”的说法。

The example is from http://docs.python.org/extending/embedding.html .该示例来自http://docs.python.org/extending/embedding.html

I would suggest Python over Lua, even though Lua is also nice.我会建议 Python 而不是 Lua,即使 Lua 也不错。

I've had a lot of success adding embedded scripting to my C++ applications using AngelScript.我使用 AngelScript 将嵌入式脚本添加到我的 C++ 应用程序中取得了很大的成功。 I've found it very easy to bind and the syntax to be very comfortable, but it depends on your target audience.我发现它很容易绑定,语法也很舒服,但这取决于你的目标受众。 I found Lua to be very fast and relatively easy to bind, but the syntax was a bit uncomfortable to me.我发现 Lua 非常快并且相对容易绑定,但语法对我来说有点不舒服。 AngelScript is very C/C++ like which I find very easy to understand and maintain, but to someone who spends more of their time working with CSS or HTML, might find it cumbersome and the language idioms might not translate well.. AngelScript 非常像 C/C++,我觉得它很容易理解和维护,但对于那些花费更多时间使用 CSS 或 HTML 的人来说,可能会觉得它很麻烦,而且语言习语可能翻译得不好。

http://www.angelcode.com/angelscript/ http://www.angelcode.com/angelscript/

http://www.gamedev.net/forum/49-angelcode/ http://www.gamedev.net/forum/49-angelcode/

Just realized I had answered a similar question here:刚刚意识到我在这里回答了一个类似的问题:

https://stackoverflow.com/questions/191222/what-is-a-good-embeddable-language-i-can-use-for-scripting-inside-my-software https://stackoverflow.com/questions/191222/what-is-a-good-embeddable-language-i-can-use-for-scripting-inside-my-software

You might be interested in ObjectScript您可能对ObjectScript感兴趣

ObjectScript, OS for short, is a new programming language. ObjectScript,简称OS,是一种新的编程语言。 It's free, cross-platform, lightweight, embeddable and open-source.它是免费的、跨平台的、轻量级的、可嵌入的和开源的。 It combines the benefits of multiple languages, including: JavaScript, Lua, Ruby, Python and PHP. 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! 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!

Minimal program used ObjectScript could be like this使用 ObjectScript 的最小程序可能是这样的

#include <objectscript.h>
using namespace ObjectScript;
int main(int argc, char* argv[])
{
    OS * os = OS::create(); // craete ObjectScript instance
    os->require("main.os"); // run ObjectScript program
    os->release();          // release the ObjectScript instance
    return 0;
}

TCL would be another option for an easy to embed scripting language. TCL 将是易于嵌入的脚本语言的另一种选择。

personally I'd go with the scripting language you and/or whoever will be using the scripting language is most familiar with already, especially if end users will be able to run custom scripts, you will need to know what, if any, languages they are familiar with in their business domain eg CAD/CAM people may know TCL, gaming people may know Lua etc.就我个人而言,我希望 go 使用您和/或将使用该脚本语言的任何人已经最熟悉的脚本语言,特别是如果最终用户能够运行自定义脚本,您将需要知道他们使用的语言(如果有的话)熟悉他们的业务领域例如CAD / CAM人可能知道TCL,游戏人可能知道Lua等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM