Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sum = function(arrays)
- local sum = 0
- for _, array in ipairs(type(arrays) == "table" and arrays or {arrays}) do
- for _, number in ipairs(array) do
- sum = sum + (tonumber(number) or 0)
- end
- end
- return sum
- end
- local meta = function(...)
- local metatable = {}
- metatable.__add = function(this, other)
- return setmetatable({sum({this, other})}, metatable)
- end
- metatable.__call = function(this)
- return this[1]
- end
- return setmetatable({...}, metatable)
- end
- local x = meta(1, 5, 10)
- local y = meta(100, 500)
- local z = meta(304, 41, 90, 69)
- print((x + y + z)()) --> 1120
Advertisement
Add Comment
Please, Sign In to add comment