lua 基本语法

gStringTable = {"a","b","c","d","e"}

for i=1,table.getn(gStringTable) do
    print(gStringTable[i])
end

for i=1,#gStringTable do
    print(gStringTable[i])
end

gNumberTable = {10,5,7,2,3,2}
table.sort(gNumberTable)

for i=1,#gNumberTable do
    print(gNumberTable[i])
end

table.insert(gNumberTable,1);
print(table.concat(gNumberTable,","))

table.remove(gNumberTable);
print(table.concat(gNumberTable,","))

table的常用函数:

table.getn()函数,返回table中元素的个数。

table.sort()函数,将table中的元素从小到大排列。

table.insert(pTable, position, value) 函数在table中插入一个新值,位置参数如果没指定,则默认将新值插入到table的末尾。

table.remove(pTable, position) 函数从指定table中删除指定位置的元素并返回该元素,如果没有指定删除的位置,则默认删除table的最后一个元素。

原文地址:https://www.cnblogs.com/as3lib/p/4120139.html