Advertisement
Guest User

Untitled

a guest
Apr 6th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1.  
  2. local colors = require("colors")
  3. local sides = require("sides")
  4. local rs = component.redstone
  5.  
  6. local messages = {
  7.   ["lights"] = {
  8.     --Syntax: ["keyword"] = {function, all, other, arguments}
  9.     ["on"] = {rs.setBundledOutput, sides.back, colors.cyan, 15},
  10.     ["off"] = {rs.setBundledOutput, sides.back, colors.cyan, 0}
  11.   },
  12.   ["door"] = {
  13.     ["open"] = {rs.setBundledOutput, sides.back, colors.magenta, 15},
  14.     ["close"] = {rs.setBundledOutput, sides.back, colors.magenta, 0}
  15.   }
  16. }
  17.  
  18. local function getFunction(tbl, msg)
  19.   for i,j in pairs(tbl) do
  20.     if msg:find(i) then
  21.       if type(j) == "table" then
  22.         if j[1] and type(j[1]) ~= "table" then
  23.           return j
  24.         end
  25.         return getFunction(j, msg)
  26.       end
  27.     end
  28.   end
  29. end
  30.  
  31. local function parseMessage(msg)
  32.   return pcall(table.unpack(getFunction(messages, msg)))
  33. end
  34.  
  35. local testmsg = "Please turn the lights on"
  36. local result, response = parseMessage(testmsg)
  37. print(result)
  38. print(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement