I have a Lua function that returns a dictionary table, and one of the values that's put into the returned table is another table as demonstrated in the following Lua function.
function tableWithinTable()
local ret = {}
ret["a"] = 1
ret["b"] = {1,2,3}
ret["c"] = 3
return ret
end
How would I go about accessing that inner table?
I know I can get to the table, because I can enter the following if statement. My current attempt at reading the table is included as well.
lua_pushstring("b");
lua_gettable(lua,1);
if(lua_istable(lua,-1))
{
//whatever is in here is executed.
lua_pushnumber(lua,1);
lua_gettable(lua,-1); //crashes to desktop here
std::cout << lua_tonumber(lua,-1) << std::endl;
lua_pop(lua,1);
}
I'm pretty sure there's an easy solution to this, but I'm totally stumped. Any help would be much appreciated.
luadeclared and initialized in your C++ code? - smockingifstatement. You push a string, and then ask if the string is a table. That will never be true. So odds are good that this isn't your actual code, or you're getting other problems. - Nicol Bolas