转自:http://blog.sina.com.cn/s/blog_4a2e9af90100cv1z.html
1.table.getn(tableName)
--等同于操作符 #
作用:得到一个table的大小。
注意:该table的key必须是有序的,索引是从1开始的。
例如:
a)有序table:
local table1 = {10, 20, 30, 50, 1000};
用table.getn(table1) 或 #table1 得到 5。
b) 无序table:
local table2 = {
["bb"] = 1,
["cc"] = 2,
["dd"] = 3,
["ee"] = nil,
["ff"] = 4,
}
用table.getn(table2) 或 #table2 无法得到正确的大小。
这种table如果想得到大小一般我这样做:
local count = 0
for k,v in pairs(table2) do
count = count + 1
end