Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Counter = setmetatable({}, {
- __call = function(self, args)
- return setmetatable({n = type(args) == "table" and -1 or 1}, {
- __call = function(self, args, ...)
- if type(args) == "table" then
- self.n = self.n - 1
- elseif type(args) == "string" then
- self.n = self.n * 2
- else
- self.n = self.n + 1
- end
- return self
- end,
- __tostring = function(self)
- return tostring(self.n)
- end
- })
- end
- })
- print(Counter()) -- 1
- print(Counter()()) -- 2
- print(Counter()()()()()()()()()()()()()()()()()()) --18
- print(Counter{}{}{}{}) -- -4
- print(Counter{}(){}()) -- 0
- print(Counter()()"""""""") -- 32
- print(Counter()(){}""""{}()) -- 5
Add Comment
Please, Sign In to add comment