lua 之如何便利数组和table
2014-02-25 01:00
471 查看
方法一,可以用for来遍历:
#后面接一个数组或者tabe来遍历它,i是该table或者数组的起始下标。
方法2:
这种是采用迭代器的方式遍历的,i为下标,v为table或者数组的值。
方式3:
i为table或者数组的下标。
方式4:
注:type(v)
功能:返回参数的类型名("nil","number", "string", "boolean", "table", "function", "thread", "userdata")
do table_week = { "w", "e", "r", "t", "y", "u", "i", } for i = 1, #table_week do print(table_week[i]) end end
#后面接一个数组或者tabe来遍历它,i是该table或者数组的起始下标。
方法2:
do table_week = { "w", "e", "r", "t", "y", "u", "i", } for i, v in pairs(table_week) do print(i) end end
这种是采用迭代器的方式遍历的,i为下标,v为table或者数组的值。
方式3:
do table_week = { "w", "e", "r", "t", "y", "u", "i", } for i in pairs(table_week) do print(i); end end
i为table或者数组的下标。
方式4:
do table_view = { "w", "e", "r", color1 = "red", color2 = "blue", {"a1", "a2", "a3"}, {"b1", "b2", "b3"}, {"c1", "c2", "c3"}, } for i, v in pairs(table_view) do if type(v) == "table" then for new_table_index, new_table_value in pairs(v) do print(new_table_value) end else print(v) end end end
注:type(v)
功能:返回参数的类型名("nil","number", "string", "boolean", "table", "function", "thread", "userdata")
相关文章推荐
- 如何在lua中打印一个数组(table)
- 如何判断lua是不是一个纯数组类的table
- lua中table如何安全移除元素
- Lua: 在C++中将table如何传入到lua中
- lua_table结构高级运用--多维数组及pairs函数
- LUA TABLE 遍历数组的应用
- lua------遍历数组和table
- 在lua中如何remove掉table里面的数据
- Lua中使用table实现的其它5种数据结构(数组、链表、队列、集合和包、StringBuild)
- Cocos2dx_Lua中table如何安全移除元素
- 关于如何释放lua table占用的内存
- cocos lua绑定感悟---tolua_isusertable及lua如何访问cocos静态函数的方法
- C 调用 LUA时候如何push table self
- LUA TABLE 遍历数组的应用
- 如何在Lua与C/C++之间实现table数据的交换
- lua 和 C 语言进行交互 —— 如何传递table
- Lua: 在C++中将table如何传入到lua中
- lua学习笔记15:table数组逆序
- c++如何接收从luaJit 的lua文件传送的table数据?
- lua 和 C 语言进行交互 —— 如何传递table