首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Lua Table相干函数

2012-12-26 
Lua Table相关函数转自:http://blog.chinahr.com/blog/pxss/post/19550???table.concat(table [,sep[,i[,j

Lua Table相关函数

转自:http://blog.chinahr.com/blog/pxss/post/19550?

?

?

table.concat(table [,sep[,i[,j]]]):

从第i个位置开始,到j为止,每隔一个元素插入一个sep.返回他们生成的字符串.默认i=1,j=长度.如果省略了后面三个参数,则返回一个table元素组成的字符串.table中的元素只能是字符串或数值.不能是function,table等.

table.insert(table [,pos],value)

将value插入到table中的第pos个位置上,默认pos=长度+1.value为基本类型(string/number)

table.remove(table [,pos])移除第pos个函数,结果返回移除掉的元素.默认是最后个

table.foreach(table,f)

table.foreachi (table, f)

table.getn(table):返回元素个数.

table.setn(table,n):设置长度.

table.sort(table [,cmp])

按cmp给的方式排序,cmp是一个比较函数.比如,

cmp=function(a,b)
?if a>b then
??return true
??? else
? ??return false
? ?end
end

table.sort(t,cmp)则t中的元素会从大到小排序.

热点排行