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
基础教程推荐
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
