如何从C ++读取Lua表返回值 [英] How to read Lua table return value from C++
本文介绍了如何从C ++读取Lua表返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Lua函数返回表(包含字符串集)
函数使用此代码运行良好:
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);
函数返回一个表。如何从我的C ++代码读取它的内容?
the function returns a table. How do I read it's contents from my C++ code?
推荐答案
如果你要求如何遍历结果表, a href =http://www.lua.org/manual/5.1/manual.html#lua_next> lua_next (该链接还包含一个示例)。如 egarcia 所说,如果 lua_pcall
返回0,则返回的函数的表可以在堆栈顶部找到。
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.
这篇关于如何从C ++读取Lua表返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文