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

c1 = newCounter()
c2 = newCounter()

print(c1())
print(c1())
print(c1())
print(c1())
print(c1())
print(c1())
print("\n")

print(c2())
print(c2())
print(c2())
print(c2())

1
2
3
4
5
6


1
2
3
4

 

相关文章:

  • 2021-07-29
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-12-24
  • 2021-08-26
猜你喜欢
  • 2022-02-14
  • 2021-12-05
  • 2022-01-22
  • 2021-08-05
  • 2021-05-17
  • 2021-08-27
  • 2021-05-19
相关资源
相似解决方案