编辑代码

function newCounter()
local count = 0
    return function () --匿名函数
        count = count + 1
        return count
    end
end

c1 = newCounter()
print(c1())
print(c1())

print()

c2 = newCounter()
print(c2())
print(c1())
print(c2())