在C ++中嵌入Lua [英] Embedding Lua in C++
问题描述
我一直在尝试将lua嵌入到c ++应用程序中,但由于编译器抱怨lua_open,我使用Lua 5.2。
I've been trying to embed lua in a c++ application but to no avail since the compiler complains about "lua_open".I'm using Lua 5.2.
我发现很多文章声称lua_open()在第五个版本被替换,但没有人提到了什么。
I found alot of articles claiming that lua_open() was replaced in the fifth version but none of them mentioned with what.
这是我想要编译的代码
extern "C" {
#include "../lua/lua.h"
#include "../lua/lualib.h"
#include "../lua/lauxlib.h"
}
int main()
{
int s=0;
lua_State *L = lua_open();
// load the libs
luaL_openlibs(L);
luaL_dofile(L,"example.lua");
printf("\nDone!\n");
lua_close(L);
return 0;
}
推荐答案
lua 5.2参考手册中未提及$ c> lua_open 函数>
Indeed, the lua_open
function is not mentioned in the lua 5.2 reference manual
A lua_State
是由 lua_newstate
您可以使用 luaL_newstate
从 lauxlib.h
A lua_State
is constructed with lua_newstate
, and you can use luaL_newstate
from lauxlib.h
A更快的方式来获得这样的问题的答案是看看Lua 5.2源代码(我刚刚做)。
A faster way to get the answers to such question is to look into the Lua 5.2 source code (which I just did).
这篇关于在C ++中嵌入Lua的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!