lua之 unpack

来源:互联网 发布:现货白银软件 编辑:程序博客网 时间:2024/06/06 10:06

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

[cpp] view plain copy
  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  
0 0
原创粉丝点击