当前位置 : 主页 > 网络编程 > lua >

Lua用table模拟数组

来源:互联网 收集:自由互联 发布时间:2021-06-23
1 local array = {}; 2 local row1 = { 1 , 3 , 5 , 7 , 9 } 3 local row2 = { 2 , 4 , 6 , 8 , 10 } 4 local row3 = { " I " , " love " , " lua " } 5 array[ 1 ] = row1; 6 array[ 2 ] = row2; 7 array[ 3 ] = row3 8 print ( " length = " , # array); 9
 1 local array = {};
 2 local row1 = {1, 3, 5, 7, 9}
 3 local row2 = {2, 4, 6, 8, 10}
 4 local row3 = {"I", "love", "lua"}
 5 array[1] = row1;
 6 array[2] = row2;
 7 array[3] = row3
 8 print("length = ", #array);
 9 for i = 1, #array do
10     for j = 1, #array[i] do
11         print(array[i][j])
12     end
13 end
网友评论