nir nir - 5 months ago 44
C++ Question

How to read Lua table return value from C++

I have a Lua function that returns table (contains set of strings)
the function run fine using this code:

lua_pushstring (lua, "funcname");
lua_gettable (lua, LUA_GLOBALSINDEX);
lua_pushstring(lua, "someparam");
lua_pcall (lua, 1, 1, 0);

the function returns a table. How do I read it's contents from my C++ code?

sbk sbk

If you are asking how to traverse the resulting table, you need lua_next (the link also contains an example). As egarcia said, if lua_pcall returns 0, the table the function returned can be found on top of the stack.