Search code examples
c++lualuabridge

Accessing Tables In Lua From C++


I have a global table in Lua I am trying to access from C++. Here is essentially what I am trying to do:

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];

I get an error on my cout, saying:

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

However I do not think these errors are the issue.

How can I access this value?


Solution

  • You have to explicitely convert your myTable[] to something << can handle.

    And your Lua array starts at 1, but you access [0].