我一直在尝试将 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("
Done!
");
lua_close(L);
return 0;
}
确实,lua_open函数/5.2/manual.html#4" rel="noreferrer">lua 5.2 参考手册
Indeed, the lua_open
function is not mentioned in the lua 5.2 reference manual
一个lua_State
是用lua_newstate
构造的,你可以使用lauxlib.h
中的luaL_newstate
A lua_State
is constructed with lua_newstate
, and you can use luaL_newstate
from lauxlib.h
获得此类问题答案的更快方法是查看 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!