从C++中访问Lua中的表格

我有一个全局 Lua 表格,想要从 C++ 中访问。 以下是我要做的事情:

Lua:

myTable = {}
myTable[1] = 1

C++:

lua_State* L = luaL_newstate();
luaL_openlibs(L);
lua_pcall(L, 0, 0, 0);
lua_State* L2 = luaL_newstate();
luaL_dofile(L, "luaScript.lua");

LuaRef myTable= getGlobal(L, "myTable");

cout << myTable[0];

我在 cout 上遇到了一个错误,错误信息是:

Error C2593 'operator <<' is ambiguous ConsoleApplication2" & "more than one operator "<<" matches these operands:

然而,我认为这些错误并不是问题所在。

我该如何访问这个值?

点赞
用户5695504
用户5695504

你必须明确地将 myTable[] 转换成一些可以处理的东西。

而且你的 Lua 数组从 1 开始,但是你却访问了 [0]

2016-01-06 20:50:48