如何将字符串包含到C/C++文件中?
$ luac -o test -s test.lua
$ cat test
LuaS�
xV(w@@A@$@&�printTestj现在,如果您可以将这个字节字符串插入到一个C/C++文件中,那么您实际上可以
luaL_loadfile(lua, bytestring.c_str());这使得没有必要在运行时加载test.lua。您甚至不必在运行时解释test.lua,对吗?
更新:
对这个问题的前两个注释有助于生成字节字符串,以便您可以将其包含在C/C++代码中。从这个答案我有个想法:
xxd -i test > test.h它产生了这样的结果:
unsigned char test[] = {
0x1b, 0x4c, 0x75, 0x61, 0x53, 0x00, 0x19, 0x93, 0x0d, 0x0a, 0x1a, 0x0a,
0x04, 0x08, 0x04, 0x08, 0x08, 0x78, 0x56, 0x00, /* ... */, 0x00};
unsigned int test_len = 105;这很好,但是这不适用于负载串,因为
该函数使用lua_load加载以零结尾的字符串s中的块。
注意:在test中有0作为数据。
https://stackoverflow.com/questions/55140109
复制相似问题