lua select 用法

分類:編程 時間:2017-02-21

調用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  


Tags: function 字符串 local count 開關

文章來源:


ads
ads

相關文章
ads

相關文章

ad