Advertisement
konalisp

someshit.lua

May 22nd, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  1. function newCounter ()
  2.     local i = 0
  3.     return function ()   -- anonymous function
  4.         i = i + 1
  5.         return i
  6.     end
  7. end
  8.  
  9. function demo ()
  10.     local c1, c2, x
  11.     c1 = newCounter()
  12.     c2 = newCounter()
  13.     x = 1
  14.     while x <= 10 do
  15.         io.write("c1 is now ", c1(), "\n")
  16.         x = x + 1
  17.     end
  18.     io.write("c2 is still only ", c2(), "\n")
  19. end
  20.  
  21. function try (a)
  22.     for i=1, 5 do
  23.         print(a)
  24.     end
  25. end
  26.  
  27. function try2 (a)
  28.     for i in ipairs(a) do
  29.         print(i)
  30.     end
  31. end
  32.  
  33. try("magical")
  34. try2({1,2,3,o=77,4})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement