Lua之UnPack

unpack它接受一个数组(table)作为参数,并默认从下标1开始返回数组的所有元素,例子代码如下:

  1. do  
  2.     arrayData = {"a", "b", "c", "d", "e"};  
  3.   
  4.     function returnMoreValues()  
  5.         return 1, 2, 3;  
  6.     end  
  7.   
  8.     a, b, c = returnMoreValues();  
  9.   
  10.     --print(a, b, c);  
  11.   
  12.     --print((returnMoreValues()));  
  13.   
  14.     --print(arrayData); -- print the address of the arrayData  
  15.     --print(unpack(arrayData)); -- print all the elements of the arrayData  
  16.     print(unpack(arrayData, 2)); --the second param is the index of the arrayData  
  17.   
  18. end 
posted @ 2016-09-08 15:18  何人之名  阅读(2042)  评论(0)    收藏  举报