Advertisement
Guest User

startup

a guest
Mar 28th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | None | 0 0
  1. peripheral.wrap("back")
  2.  
  3. local Commands = {
  4.   ["core"] = {
  5.     ["args"] = {
  6.       {
  7.         name = "state",
  8.         typeof = "string"
  9.       }
  10.     },
  11.     ["function"] = {
  12.       func = function(self, args)
  13.         print("CORE")
  14.       end
  15.     }
  16.   }
  17. }
  18.  
  19. local function parseCommand(command)
  20.   if command == nil then return end
  21.  
  22.   local args = {}
  23.   local cmd = ""
  24.   local firstrun = true
  25.  
  26.   for i in command:gmatch("%S+") do
  27.     if firstrun then
  28.       cmd = i
  29.       firstrun = false
  30.     else
  31.       args[#args + 1] = i
  32.     end
  33.   end
  34.   return cmd, args
  35. end
  36.  
  37. while true do
  38.   local _, command = os.pullEvent("chat_command")
  39.   local cmd, args = parseCommand(command)
  40.    
  41.   if commands[cmd] ~= nil then
  42.     local wrongArg = false
  43.     for index, value in pairs(Commands[cmd]["args"]) do
  44.       if value.typeof ~= type(args[index]) then
  45.         args[index] = tonumber(args[index])
  46.         if args[index] == nil then
  47.           wrongArg = "type"
  48.           break
  49.         end
  50.       end
  51.     end
  52.    
  53.     if wrongArg then
  54.       local argsString = ""
  55.       for i,_ in pairs(Commands[cmd]["args"]) do
  56.         argsString = argsString.." ["..Commands[cmd]["args"][i]..name.."]"
  57.       end
  58.     end
  59.   end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement