調(diào)用select時,必須傳入一個固定實參selector(選擇開關)和一系列變長參數(shù)。如果selector為數(shù)字n,那么select返回它的第n個可變實參,否則只能為字符串"#",這樣select會返回變長參數(shù)的總數(shù)。例子代碼:
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