C++中遍历lua table
2013-03-20 19:29
190 查看
int lua_next (lua_State *L, int index);
Pops a key from the stack, and pushes a key-value pair from the table at the given index (the "next" pair after the given key). If there are no more elements in the table, then
lua_nextreturns 0 (and pushes nothing).
A typical traversal looks like this:
/* table is in the stack at index 't' */ lua_pushnil(L); /* first key */ while (lua_next(L, t) != 0) { /* uses 'key' (at index -2) and 'value' (at index -1) */ printf("%s - %s\n", lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); }
While traversing a table, do not call
lua_tolstringdirectly on a key, unless you know that the key is actually a string. Recall that
lua_tolstringchanges the value at the given index; this confuses the next call to
lua_next.
相关文章推荐
- C/C++ 中遍历 Lua table 完整版
- C++遍历Lua二维table
- C/C++遍历Lua中的table
- C/C++ 中遍历 Lua table 完整版
- c++遍历lua table示例
- c++返回table给lua
- 5、C++读取Lua中Table的内容
- c++读取lua中的table
- 浅析Lua中table的遍历
- C++返回table给lua
- Lua 的table遍历 【转】
- 6、C++修改Lua中Table的内容
- lua table 遍历
- lua中遍历table的几种方式比较
- 浅析Lua中table的遍历
- Lua 小白关于Table遍历的一点笔记
- lua 与 c/c++ 交互(3)c/c++ 调用 lua 数组类型 table
- c/c++_Lua交互----关于Lua中table类型的使用实例
- c++获取lua嵌套table某属性的值