/soap/.services/math.lua



   1   
   2   -- Copied from http://barracudaserver.com/ba/doc/en/lua/soap.html
   3   
   4   soap_services = {
   5   
   6     Math = { -- service definition
   7   
   8       Add = { -- operation
   9         input = {{name = "x", type = "double"},{name = "y", type = "double"}},
  10         output = {name = "return",type = "double"},
  11         call = function(x,y) return x+y end
  12       },
  13   
  14       Subtract = { -- operation
  15         input = {{name = "x", type = "double"},{name = "y", type = "double"}},
  16         output = {name = "return",type = "double"},
  17         call = function(x,y) return x-y end
  18       },
  19   
  20       Multiply = { -- operation
  21         input = {{name = "x", type = "double"},{name = "y", type = "double"}},
  22         output = {name = "return",type = "double"},
  23         call = function(x,y) return x*y end
  24       },
  25   
  26       Divide = { -- operation
  27         input = {{name = "x", type = "double"},{name = "y", type = "double"}},
  28         output = {name = "return",type = "double"},
  29         call = function(x,y) return x/y end
  30       },
  31   
  32       Sum = { -- operation to sum an array of doubles
  33         input = {name = "t", type = "doubleArray"},
  34         output = {name = "return",type = "double"},
  35         call = function(t)
  36                local tot = 0
  37                for i,v in ipairs(t) do tot = tot+v end
  38                return tot
  39              end
  40       },
  41   
  42       RandomInt = { -- return random integer in the range 0-n
  43         input = {name = "range", type = "integer"},
  44         output = {name = "return",type = "integer"},
  45         call = function(range) return ba.rnd(0,range) end,
  46       },
  47   
  48     } -- end of Math service definition
  49   }