1 table表遍历
a = {["hjj"] = 2, ["hss"] = 3, 4}
for k,v in ipairs(a) do
print(k,v)
end
print("\r\n")
for k,v in pairs(a)do
print(k,v)
end
输出结果
heollow World
1 4
1 4
hjj 2
hss 3
2 二维数组
a = {}
i = 0
for i = 1,10 do
a[i]= {}
for j =1 , 10 do
a[i][j] = j
end
end
for i = 1,10 do
for j =1 , 10 do
print(a[i][j])
end
end
3 Table表构建类
A = {["width"] = 123, ["length"] = 3}
function A.area(width, length)
A.width = width
A.length = length
A.area = width * length
end
function A.OutData()
print("area "..A.area)
end
A.area(1,3)
A.OutData()
输出结果: area 3