Closures
Same rules as Lua: closures capture variables, not values. Arrow functions for the short ones.
local function makeCounter()
local n = 0
return function()
n = n + 1
return n
end
end
local tick = makeCounter()
tick(); tick()
print(tick()) -- 3 func makeCounter():
local n = 0
return () => ++n
tick = makeCounter()
tick(); tick()
print(tick()) // 3