(四)Lua Table

(1)可以用任意類型的值來作數組的索引,但這個值不能是 nil;

(2)table 是不固定大小的,可根據需要自由擴容;

(3)Table 的操作:

操作 使用
連接 table.concat (table [, sep [, start [, end]]]);
插入

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

刪除 table.remove (table [, pos]);
排序

(1)table.sort (table [, comp]);

(2)默認升序排序;

賦值

local a_table = { 1 , 2 , 3 };

local b_table = a_table;

a_table = nil;

print( b_table[1] )     --  1

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章