若怯若愚

大勇若怯,大智若愚

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
可以返回多值
 1 function getGreen(ta)
 2     local taKey = 1
 3     local taValue = ta[taKey]
 4 
 5     for i, val in ipairs(ta) do
 6         if val == "Green" then
 7             taKey = i
 8             taValue = val
 9 
10             break
11         end
12     end
13 
14     return taKey, taValue
15 end
16 
17 color = {"Red""Green""Yellow"}
18 print(getGreen(color))            -- 輸出結果:2       Green
可接受可變參數
1 function getGreen()    -- "" 表示可變參數
2     
3 end
posted on 2009-04-09 17:06  考巴熊  阅读(167)  评论(0编辑  收藏  举报