简体   繁体   English

将ac和lua程序编译为单个可执行文件

[英]compiling a c and lua program into a single executable

I have a program written in a combination of c and lua. 我有一个用c和lua组合编写的程序。 I know how to compile c programs, and I know how to compile lua programs, but I don't know how I can compile a hybrid program into a single executable. 我知道如何编译c程序,也知道如何编译lua程序,但是我不知道如何将混合程序编译为单个可执行文件。 It's also important to note that I'm using the lua c api. 同样重要的是要注意我正在使用lua c api。

EDIT: just to clarify, I'm not using the lua interpreter in anyway shape or form. 编辑:只是为了澄清,我不以任何形式使用lua解释器。

I thing the easiest way would be to store you program a string and then use the luaL_dostring() function to execute it. 我想最简单的方法是存储一个字符串程序,然后使用luaL_dostring()函数执行它。

I did not check but I'm pretty sure you can compile the Lua code with luac and store it in a char [] buffer instead of storing the script source code. 我没有检查,但是我很确定您可以使用luac编译Lua代码并将其存储在char []缓冲区中,而不是存储脚本源代码。 This will speed up things a bit by doing the compilation of the source code to Lua VM bytecode once for all at compile time (rather than at runtime). 通过在编译时(而不是在运行时)一次全部将源代码编译为Lua VM字节码,可以加快处理速度。

Something like: 就像是:

const char *luacode = "print('Hello')";
lua_State *L;
...
...

   luaL_dostring (L, luacode);

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

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