Lua 也工作得很好,特别是因为它很小,符合 ANSI C 标准,内存占用少,还有很棒的 wiki 和消息列表。如果您需要更快的速度,可以使用 x86 32 和 64 位 jit 版本(luajit)。绑定可以通过一系列工具/库来完成,例如 swig 或lunar(wiki 列出了所有这些)。我能看到的唯一问题是绑定结构成员,以便可以直接引用它们(即:struct.member = 4),尽管可以使用具有绑定到变量名的 get 和 set 方法的元表来设置它
Lua works pretty well too, especially since its small, is ansi c compliant, has a low memory foot print along with a great wiki and messaging list. If you need even more speed there is a x86 32 and 64 bit jit version(luajit). Binding can be done with an array of tools/libraries, like swig or lunar(the wiki lists them all). The only problem that i can see is binding the struct members so they can be referenced directly(ie: struct.member = 4), though its possible to set this up with metatables that have get and set methods bound to variable names
You say that you're not looking for something to wrap your C++ functions / classes in a Python interface, but if you want Python code to be able to refer to members of your C++ my_integers structure, that is wrapping C++ classes in a Python interface. Of course, you're free to wrap as many or as few classes as you want - in this example, you'd wrap my_integers, then you'd embed a Python interpreter to do stuff with my_integers.
For something as simple as you describe, you could implement an interpreter for your own 'little language'. You could even call it the "Robin" language. ;-)
I advice using Lua as internal scripting engine. Implementation is just a few lines, and though light, the language has sufficient power. So no need for TCL. You might as well look at python, integration in C++ is rather easy, as there exists a Boost.Python implementation facilitating integration.
But depending on the application, I'd still recommend Lua.
发布评论
评论(9)
为什么不使用 Boost.Python?您可以将数据类公开给 Python 并执行脚本/函数,如下所述 此处。
Why not use Boost.Python? You can expose your data classes to Python and execute a script/function as described here.
Python 文档中有一个关于在 C 或 C++ 应用程序中嵌入 Python 的页面。
The Python documentation has a page on embedding Python in a C or C++ application.
如果您只想从 C/C++ 运行 Python 脚本,请使用 Python C API。在 C/C++ 代码中:
对于更复杂的事情,您必须查看 API 文档,但这非常简单。
If you want to simply run Python scripts from C/C++, then use the Python C API. In your C/C++ code:
For more complicated things, you will have to look at the API docs, but it's pretty straightforward.
嵌入 JavaScript 引擎(例如 V8)怎么样?
How about embedding a JavaScript engine, such as V8?
不要忘记嵌入式脚本语言的鼻祖 - tcl。
tcl 有很好的 c++ 包装器(在 boost.python 上建模),这使得调用回调并将回调连接到代码变得很简单
dont forget the grand-daddy of embedded scripting language - tcl.
tcl has v nice c++ wrapper (modelled on boost.python) that makes it trivial to invoke and to wire up callbacks to your code
Lua 也工作得很好,特别是因为它很小,符合 ANSI C 标准,内存占用少,还有很棒的 wiki 和消息列表。如果您需要更快的速度,可以使用 x86 32 和 64 位 jit 版本(luajit)。绑定可以通过一系列工具/库来完成,例如 swig 或lunar(wiki 列出了所有这些)。我能看到的唯一问题是绑定结构成员,以便可以直接引用它们(即:struct.member = 4),尽管可以使用具有绑定到变量名的 get 和 set 方法的元表来设置它
Lua works pretty well too, especially since its small, is ansi c compliant, has a low memory foot print along with a great wiki and messaging list. If you need even more speed there is a x86 32 and 64 bit jit version(luajit). Binding can be done with an array of tools/libraries, like swig or lunar(the wiki lists them all). The only problem that i can see is binding the struct members so they can be referenced directly(ie: struct.member = 4), though its possible to set this up with metatables that have get and set methods bound to variable names
您说您并不是在寻找将 C++ 函数/类包装在 Python 接口中的东西,但如果您希望 Python 代码能够引用 C++
my_integers
结构的成员,那么 < em>正在将C++类包装在Python接口中。当然,您可以随意包装任意数量的类 - 在此示例中,您将包装my_integers
,然后 嵌入 Python 解释器 来使用my_integers
进行操作。You say that you're not looking for something to wrap your C++ functions / classes in a Python interface, but if you want Python code to be able to refer to members of your C++
my_integers
structure, that is wrapping C++ classes in a Python interface. Of course, you're free to wrap as many or as few classes as you want - in this example, you'd wrapmy_integers
, then you'd embed a Python interpreter to do stuff withmy_integers
.对于像您描述的那样简单的事情,您可以为您自己的“小语言”实现一个解释器。您甚至可以将其称为“Robin”语言。 ;-)
For something as simple as you describe, you could implement an interpreter for your own 'little language'. You could even call it the "Robin" language. ;-)
我建议使用 Lua 作为内部脚本引擎。实现只有几行,虽然很轻,但该语言具有足够的功能。所以不需要TCL。您不妨看看 python,C++ 中的集成相当容易,因为存在 Boost.Python 实现促进集成。
但根据应用程序,我仍然推荐 Lua。
I advice using Lua as internal scripting engine. Implementation is just a few lines, and though light, the language has sufficient power. So no need for TCL. You might as well look at python, integration in C++ is rather easy, as there exists a Boost.Python implementation facilitating integration.
But depending on the application, I'd still recommend Lua.