ForeverDev

Untitled

Oct 30th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. local sum = function(arrays)
  2.     local sum = 0
  3.     for _, array in ipairs(type(arrays) == "table" and arrays or {arrays}) do
  4.         for _, number in ipairs(array) do
  5.             sum = sum + (tonumber(number) or 0)
  6.         end
  7.     end
  8.     return sum
  9. end
  10.  
  11. local meta = function(...)
  12.     local metatable = {}
  13.     metatable.__add = function(this, other)
  14.         return setmetatable({sum({this, other})}, metatable)
  15.     end
  16.     metatable.__call = function(this)
  17.         return this[1]
  18.     end
  19.     return setmetatable({...}, metatable)
  20. end
  21.  
  22. local x = meta(1, 5, 10)
  23. local y = meta(100, 500)
  24. local z = meta(304, 41, 90, 69)
  25.  
  26. print((x + y + z)()) --> 1120
Advertisement
Add Comment
Please, Sign In to add comment