lua 笔记

-- print all values of array 'a'
for i,v in ipairs(a) do 
    print(v) 
end

-- print all keys of table 't'
for k in pairs(t) do 
    print(k) 
end

function newCounter()
    local i = 0
    return function()
        i = i + 1
        return i
    end
end


c1 = newCounter()

print( c1() ) --> 1

print( c1() ) --> 2

  

posted @ 2017-07-08 23:41  hao.ma  阅读(110)  评论(0编辑  收藏  举报