哪些语言生成字节码并可以在 C++ 中加载/执行?
我想知道什么语言适合这种情况:
我正在编写一个应用程序(C++),我需要为其添加某种类型的脚本支持,但这种语言必须能够“编译”。
此编译将生成某种类型的人类无法读取的“字节码”。然后我需要能够获取这个字节码,将其加载到 C++ 应用程序中并执行它。
将c++应用程序函数导出到脚本并回调脚本函数是必须的。
主要思想是在不接触 C++ 代码的情况下扩展应用程序功能,但用户阅读这些脚本一定很困难。
我可以使用哪些语言?
I'd like to know what languages fit this scenario:
I'm writing an application (C++) and I need to add some type of scripting support to it, but this language must be able to be "compiled".
This compilation will generate some type of "bytecode" that is not readable by humans. Then I need to be able to get this bytecode, load it inside the C++ application and execute it.
Exporting c++ application functions to the script and calling back script functions is a must.
The main idea is to extend application functionality without touching the C++ code, but it must be hard for a user to read these scripts.
What languages can I use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许是脑残?当然很容易找到解释器,并且比普通机器代码或字节代码可读性差得多。
Perhaps Brainfuck? Certainly easy to find interpreters, and much less readable than your average machine code or byte code.
我很乐意建议 ChaiScript,但我们没有内置任何类型的加密或字节码支持
。也就是说,您没有理由不能使用任何现有的 C++ 脚本引擎。如果您提供自己的加密和解密函数来将脚本输入引擎,那么 ChaiScript、luabind 等都可以使用。
据我所知,支持 C++ 和字节码且相对晦涩的脚本引擎是 AngelScript。他们有一个关于加载预编译字节码的页面。
I'd love to suggest ChaiScript, but we don't have any kind of encryption or bytecode support built in.
That said, there's no reason you could not use any existing C++ scripting engine. ChaiScript, luabind, etc, could all be used if you provide your own encryption and decryption functions for feeding the script into the engine.
The one scripting engine that I know of that supports c++ and bytecode and is relatively obscure is AngelScript. They have a page on loading pre-compiled bytecode.
也许 Vox* 可以满足您的需求?
这些脚本可以预编译成可移植的字节码,并且非常容易嵌入,具有类似于 Lua 的基于堆栈的 API:
有关更完整功能的示例,请参阅 etc/minimal.cpp 和 src/frontend/frontend.cpp
* Vox 是一个项目为了个人目的,我一直在努力取代 Lua。它基于 squirrel3 虚拟机的高度修改版本(但不再与 squirrel 兼容!)。
语法也发生了一些变化:它不再使用
<-
来表示新槽,而是使用:=
来避免语法不明确。Core 已经完成并可以在嵌入式项目中使用,但 stdlib 尚未完成,因为 Vox 是一个非常年轻的项目(因此,目前缺乏文档,但 stdlib 是嵌入式编程的一个很好的例子,以及通用脚本编写的示例)。
Maybe Vox* can fit your bill?
The scripts can be precompiled into portable bytecode, and is very easy to embed, with stackbased API similar to Lua:
For a more fully featured example, see etc/minimal.cpp and src/frontend/frontend.cpp
* Vox is a project that i've been working on to replace Lua for personal purposes. It's based on a highly modified version of the VM of squirrel3 (but is not compatible with squirrel anymore!).
The syntax has also changed a little: Instead of using
<-
for new slots, it uses:=
, to avoid ambigious syntax.The Core is finished and ready for use in embedded projects, but the stdlib is still unfinished, since Vox is a very young project (due to that, documentation is currently lacking, but the stdlib is a good example for embedded programming, as well as the examples for general purpose scripting).
我建议您使用 LLVM。 LLVM的中间表示可以以字节码格式存储。您将需要使用脚本语言的现有前端或开发您自己的前端。您的 C++ 应用程序可以加载字节码文件并对其进行 JIT。
这里是基于 LLVM 的现有项目列表。您可能会找到适合您需求的解决方案。
I would suggest you use LLVM. LLVM's intermediate representation can be stored in bytecode format. You will need to use an existing front-end for a scripting language or develop your own front-end. Your C++ application can load the bytecode file and JIT it.
Here is a list of existing projects based on LLVM. You might find there a solution which fits your needs.
LuaJIT 是一个漂亮、快速的 Lua 解释器,它将 Lua 即时编译为本机机器代码。与常规 Lua 不同,LuaJIT 字节码是独立于平台的。
你自己看一下:
http://luajit.org/luajit.html
http://luajit.org/extensions.html
LuaJIT is a nice, quick Lua interpreter, that JITs Lua into native machine code. LuaJIT bytecode is platform independent, unlike regular Lua.
Take a look for yourself:
http://luajit.org/luajit.html
http://luajit.org/extensions.html