Embedding Lua in C++(在 C++ 中嵌入 Lua)
问题描述
我一直在尝试将 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 中嵌入 Lua


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01