調用select時,必須傳入一個固定實參selector(選擇開關)和一系列變長參數。如果selector為數字n,那么select返回它的第n個可變實參,否則只能為字符串"#",這樣select會返回變長參數的總數。例子代碼:
do function foo(...) for i = 1, select('#', ...) do //get the count of the params local arg = select(i, ...);//select the param PRint("arg", arg); end end foo(1, 2, 3, 4); end
新聞熱點
疑難解答