Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function newCounter ()
- local i = 0
- return function () -- anonymous function
- i = i + 1
- return i
- end
- end
- function demo ()
- local c1, c2, x
- c1 = newCounter()
- c2 = newCounter()
- x = 1
- while x <= 10 do
- io.write("c1 is now ", c1(), "\n")
- x = x + 1
- end
- io.write("c2 is still only ", c2(), "\n")
- end
- function try (a)
- for i=1, 5 do
- print(a)
- end
- end
- function try2 (a)
- for i in ipairs(a) do
- print(i)
- end
- end
- try("magical")
- try2({1,2,3,o=77,4})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement