Advertisement
YellowAfterlife

Killa: Addition metafunction

May 11th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global.add = function(a, ...) {
  2.     var b = { ... }
  3.     var r = a
  4.     if (typeof(a) == 'string') {
  5.         for each (var i, v in ipairs(b)) {
  6.             r = string.add(r, v)
  7.         }
  8.     } else if (typeof(a) == 'number') {
  9.         for each (var i, v in ipairs(b)) {
  10.             r = math.add(r, v)
  11.         }
  12.     } else if (typeof(a) == 'boolean') {
  13.         // boolean + values : returns if at least one element is true
  14.         if (a) { return a }
  15.         for each (var i, v in ipairs(b)) {
  16.             if (v) { return true }
  17.         }
  18.         return a
  19.     } else if (typeof(a) == 'table') {
  20.         r = table.clone(a)
  21.         for each (var i, v in ipairs(b)) {
  22.             table.add(r, v)
  23.         }
  24.     }
  25.     return r
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement