fatboychummy

AVeryGoodCounter.lua

Nov 27th, 2020 (edited)
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. local Counter = setmetatable({}, {
  2.   __call = function(self, args)
  3.     return setmetatable({n = type(args) == "table" and -1 or 1}, {
  4.       __call = function(self, args, ...)
  5.         if type(args) == "table" then
  6.           self.n = self.n - 1
  7.         elseif type(args) == "string" then
  8.           self.n = self.n * 2
  9.         else
  10.           self.n = self.n + 1
  11.         end
  12.         return self
  13.       end,
  14.       __tostring = function(self)
  15.         return tostring(self.n)
  16.       end
  17.     })
  18.   end
  19. })
  20.  
  21. print(Counter()) -- 1
  22. print(Counter()()) -- 2
  23. print(Counter()()()()()()()()()()()()()()()()()()) --18
  24. print(Counter{}{}{}{}) -- -4
  25. print(Counter{}(){}()) -- 0
  26. print(Counter()()"""""""") -- 32
  27. print(Counter()(){}""""{}()) -- 5
Add Comment
Please, Sign In to add comment