Lua 笔记14 table库常用函数
2016-03-22 16:53
513 查看
--[[ table 库 insert函数的操作]] tbinsert={1,2,3,4,5} table.insert(tbinsert,0) --两个参数,table,和插入的值,默认插入到table最后 for _,v in pairs(tbinsert) do print(v) end table.insert(tbinsert,1,-1) 三个参数,table,插入的位子,插入的值 for _,v in pairs(tbinsert) do print(v) end
--[[ table 库 concat函数的操作]] --[[ concat是concatenate(连锁, 连接)的缩写. table.concat()函数列出参数中指定table的数组部分从start位置到end位置的所有元素, 元素间以指定的分隔符(sep)隔开。除了table外, 其他的参数都不是必须的, 分隔符的默认值是空字符, start的默认值是1, end的默认值是数组部分的总长. ]] tb1={"alpha","beta","gamma"} --concat 有3个参数 sep, start, end, --所以虽然它们都不是必须参数, --但如果要指定靠后的参数, 必须同时指定前面的参数. print(table.concat(tb1,":")) print(table.concat(tb1, "@", 1, 2)) --参数:table,分隔符,起始位子,结束位子 print(table.concat(tb1, "\n", 2, 3))
相关文章推荐
- C/C++ 如何调用Lua中的数据
- Lua笔记13 table 的__add和__index 方法
- Lua笔记12 metatable 和metamethod
- lua中字符串的分割函数
- UVa 327 - Evaluating Simple C Expressions
- 调试lua代码
- lua的Debug库
- Lua中的异常处理pcall、xpcall、debug使用实例
- 150. Evaluate Reverse Polish Notation
- 快速掌握Lua 5.3 —— 扩展你的程序 (2)
- lua 面向对象编程
- wireshark协议解析插件【LUA】示例
- tolua.cast的实用方法
- 快速掌握Lua 5.3 —— 扩展你的程序 (1)
- lua实现全排列和组合排列
- lua2c
- lua bytecode 编译
- lintcode-medium-Evaluate Reverse Polish Notation
- (转)Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境
- lua 调用.so 和 require 使用