lua之select,unpack用法,luaselectunpack


调用select时,必须传入一个固定实参selector(选择开关)和一系列变长参数。如果selector为数字n,那么select返回它的第n个可变实参,否则只能为字符串"#",这样select会返回变长参数的总数。例子代码:

  1. do  
  2.     function foo(...)  
  3.         for i = 1, select('#', ...) do //get the count of the params  
  4.             local arg = select(i, ...);//select the param  
  5.             print("arg", arg);  
  6.         end  
  7.     end  
  8.   
  9.     foo(1, 2, 3, 4);  
  10. end  
    local function show( ... )
        print("unpack(...)====",unpack(...))
        local a,b,c,d = unpack(...)
    end
    show({2,6,9,3})





相关内容

    暂无相关文章