简体   繁体   English

C/C++ 的脚本语言?

[英]Scripting language for C/C++?

Is there a scripting language for C++ (like perl) which can be used for rapid development and use some tool which can convert into C/C++ program to get higher performance for deployment?是否有 C++ 的脚本语言(如 perl)可用于快速开发并使用一些可以转换为 C/C++ 程序的工具以获得更高的部署性能?

EDIT:编辑:
Based on some commented, let me clarify the question.根据一些评论,让我澄清一下这个问题。 I should be able to convert script into C/C++ program or binary without modifying my script.我应该能够在不修改脚本的情况下将脚本转换为 C/C++ 程序或二进制文件。

With a C/C++ interpreter you can use C/C++ as a scripting language 使用C / C ++解释器,您可以使用C / C ++作为脚本语言


Note: So far, I have tried only Ch and CINT . 注意:到目前为止,我只尝试过ChCINT I have added ccons and UnderC to make the list more complete. 我添加了cconsUnderC以使列表更完整。

You may try Lua quite often used with C++ in games industry. 您可以尝试在游戏行业中经常与C ++一起使用的Lua It has a small memory footprint and is quite mature, has a great library... just give it a try. 它占用的内存很小,非常成熟,有一个很棒的库...只是试一试。

hm... I do not understand what you want to achieve: do you want to find a scripting language that will somehow, magically be converted into c++ source? 嗯...我不明白你想要实现的目标:你想找到一种可以某种方式神奇地转换成c ++源码的脚本语言吗? Or what you really want is just an option to create an executable from the script? 或者您真正想要的只是从脚本创建可执行文件的选项? If the latter - then you may try py2Exe . 如果是后者 - 那么你可以试试py2Exe

Anybody interested in a scripting language that is (mostly) very similar to C++, may want to take a look at angelscript (ZLIB): 任何对(大部分)与C ++非常相似的脚本语言感兴趣的人都可能想看看angelscript (ZLIB):

The AngelCode Scripting Library, or AngelScript as it is also known, is an extremely flexible cross-platform scripting library designed to allow applications to extend their functionality through external scripts. AngelCode脚本库或AngelScript也是一个非常灵活的跨平台脚​​本库,旨在允许应用程序通过外部脚本扩展其功能。 It has been designed from the beginning to be an easy to use component, both for the application programmer and the script writer. 它从一开始就被设计为一个易于使用的组件,适用于应用程序员和脚本编写者。

Efforts have been made to let it call standard C functions and C++ methods with no need for proxy functions. 已经努力让它调用标准C函数和C ++方法而不需要代理函数。 The application simply registers the functions, objects, and methods that the scripts should be able to work with and nothing more has to be done with your code. 应用程序只是注册脚本应该能够使用的函数,对象和方法,并且不再需要对代码进行任何操作。 The same functions used by the application internally can also be used by the scripting engine, which eliminates the need to duplicate functionality. 脚本引擎也可以使用内部应用程序使用的相同功能,从而无需复制功能。

For the script writer the scripting language follows the widely known syntax of C/C++ (with minor changes), but without the need to worry about pointers and memory leaks. 对于脚本编写器,脚本语言遵循广为人知的C / C ++语法(稍作修改),但不需要担心指针和内存泄漏。 Contrary to most scripting languages, AngelScript uses the common C/C++ datatypes for more efficient communication with the host application. 与大多数脚本语言相反,AngelScript使用通用的C / C ++数据类型来与主机应用程序进行更有效的通信。

For more info, check out: http://www.angelcode.com/angelscript/sdk/docs/manual/index.html 有关详细信息,请访问: http//www.angelcode.com/angelscript/sdk/docs/manual/index.html

Many projects combine eg C++ and Python -- see for example boost.python . 许多项目结合了例如C ++和Python - 例如参见boost.python

I prefer R and use the Rcpp interface from R to C++. 我更喜欢R并使用R到C ++的Rcpp接口。

Either case gives you your scripting language for prototyping and easy 'glue' to C++ for performance. 这两种情况都为您提供了原型设计的脚本语言,并且易于“粘合”C ++以提高性能。

pawn 典当

pawn is a simple, typeless, 32-bit extension language with a C-like syntax. pawn是一种简单的,无类型的32位扩展语言,具有类似C的语法。 A pawn "source" program is compiled to a binary file for optimal execution speed. 典当“源”程序被编译为二进制文件以获得最佳执行速度。 The pawn compiler outputs P-code (or bytecode) that subsequently runs on an abstract machine. pawn编译器输出随后在抽象机器上运行的P代码(或字节码)。 Execution speed, stability, simplicity and a small footprint were essential design criteria for both the language and the abstract machine. 执行速度,稳定性,简单性和小占用空间是语言和抽象机器的基本设计标准。

This language is very simular to c syntax, so anyone that has done any c++,c,c#,java will be able to read it and its simplyfied so none coders can read it to. 这种语言与c语法非常相似,所以任何已经完成任何c ++,c,c#,java的人都能够读取它并简化它,因此没有编码器可以读取它。 This language is currently used all around, among other places scripting against halflife 1 and halflife2 servers. 这种语言目前在各地使用,其中包括针对halflife 1halflife2服务器的脚本。

There is a new package Chaiscript which is designed for C++. 有一个专为C ++设计的新包Chaiscript It's relatively new and not completely stable yet. 它相对较新而且还不完全稳定。

For Python, I sometimes find psyco useful. 对于Python,我有时会发现psyco很有用。 Not sure if there is any equivalent for perl though. 不确定perl是否有任何等价物。

When choosing a language for a task, I find it more useful to choose the language most suited for the job. 在为任务选择语言时,我发现选择最适合该工作的语言会更有用。 If the job asks for more performance than a scripting language can provide under normal conditions, it is usually better to just switch than to bend over backwards to try to make your code fast. 如果作业要求在正常条件下提供比脚本语言更多的性能,那么通常切换比向后弯曲以尝试使代码更快更好。

GML:www.yoyogames.com

The question could be interpreted different ways... 这个问题可以用不同的方式解释......

If you have already coded a part of your application in C++ and need to add modules or scripts, that you want to add in the C++ code eventually for improved performance, you could use Qt which is a solid, very complete multi-platform framework. 如果您已经用C ++编写了应用程序的一部分并且需要添加模块或脚本,那么最终要在C ++代码中添加模块或脚本以提高性能,您可以使用Qt ,这是一个可靠,非常完整的多平台框架。

It includes support for scripts (ECMAScript, the standardized version of Javascript), from which you can access your C++ objects if you need to. 它包括对脚本的支持(ECMAScript,Javascript的标准化版本),如果需要,您可以从中访问C ++对象。 It also provides support for plug-ins. 它还为插件提供支持。

With that approach, you can even proceed in three steps, 通过这种方法,您甚至可以分三步完成,

  • first do some tests in Javascript, 先用Javascript做一些测试,
  • then code the base of your application in C++ and still use a part in scripts (for example if you need to try different algorithms), 然后使用C ++编写应用程序的基础代码,并仍在脚本中使用一部分(例如,如果您需要尝试不同的算法),
  • and finally port everything, or at least the critical parts, in C++. 最后在C ++中移植所有内容,或者至少是关键部分。

Another option is to embed a Python interpreter in your code, although that will probably require more work. 另一种选择是在代码中嵌入Python解释器,尽管这可能需要更多的工作。

I'm not sure I understand your question but if your looking to implement your own scripting language which could interface with your c++ code you can take a look at boost::spirit. 我不确定我理解你的问题但如果你想要实现自己的脚本语言可以与你的c ++代码接口,你可以看一下boost :: spirit。 You just have to tell it your grammar and you have your scripting language doing whatever you tell it to in c++. 你只需要告诉它你的语法,你就可以使用脚本语言来完成你在c ++中所做的任何事情。 You specify your grammar using c++ operators making it very easy and intuitive. 您可以使用c ++运算符指定语法,使其非常简单直观。

That's what I currently used for my recent needs and it looks like it will do the job just fine. 这就是我目前用于我最近的需求,看起来它可以正常工作。 You have full access to your c++ objects when specifying your grammar and your user can have a very simple language to learn (compared to CINT where the language would be c++ itself). 在指定语法时,您可以完全访问c ++对象,并且用户可以使用非常简单的语言进行学习(与CINT相比,语言本身就是c ++本身)。

Compile time are a little slow right now but if you don't need to implement a very complex language it should be manageable (I wouldn't like to see the compile time for something like c++). 编译时间现在有点慢但如果你不需要实现一个非常复杂的语言它应该是可管理的(我不希望看到像c ++这样的编译时间)。 Also documentation is a little lacking for the newest version (and the most up-to-date version is a little hard to find) but it's relatively easy to use so it might be worth a check, depending on your needs. 最新版本的文档有点缺乏(最新版本有点难以找到),但它相对容易使用,因此根据您的需要可能值得检查。

You could code using D programming language as both a script or a fast compiled output. 您可以使用D编程语言编写脚本或快速编译输出。

here is an article that talks in detail about D and its advantages "The Case for D" 这篇文章详细讲述了D及其优势“D案例”

粘附是对C的解释器++ 攀附

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

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