简体   繁体   English

将Lua脚本嵌入C ++应用程序中可以将Lua部分编译成机器代码吗?

[英]Will embed Lua script in C++ application compile Lua part into machine code?

I have a newbie question regarding Lua. 我有一个关于Lua的新手问题。

If I embed some Lua script inside my C++ application. 如果我在C ++应用程序中嵌入一些Lua脚本。 When I compile my C++ application, will the Lua script part be compiled into machine code or does C++ application runs the Lua script part each time with Lua interpreter? 当我编译C ++应用程序时,是将Lua脚本部分编译成机器代码,还是C ++应用程序每次都使用Lua解释器运行Lua脚本部分?

The web is saying using LuaJIT will improve embedded script performance greatly, then I guess the Lua script inside C++ application is never compiled into machine code. 网络上说使用LuaJIT将大大提高嵌入式脚本的性能,那么我想C ++应用程序内部的Lua脚本永远不会编译成机器代码。

If I would like to squeeze every bit of performance in this kind of situation, ie, I would like to write part of my program in Lua to be embedded in a C++ application. 如果我想在这种情况下压缩所有性能,即,我想用Lua编写我的程序的一部分以嵌入到C ++应用程序中。 What is my best option? 我最好的选择是什么? Is there something I can used to compile Lua part into C++/C part and will this improve performance? 我可以用来将Lua部分编译为C ++ / C部分吗,这会提高性能吗?

The entire point of a JIT compiler is to generate machine code at runtime from the source files. JIT编译器的全部目的是在运行时从源文件生成机器代码。

LuaJIT will look for 'hotspots' in your code that run frequently (such as inner loops or frequently used functions), and try to compile them to machine code. LuaJIT将在代码中寻找经常运行的“热点”(例如内部循环或常用功能),并尝试将其编译为机器代码。 It doesn't matter where the code came from; 代码来自哪里都无所谓。 after loading, that is completely irrelevant. 加载后,这是完全不相关的。

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

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