CapsAdmin

Untitled

Jul 15th, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. --command line matching
  2.  
  3. local line = [[mycmd hey arg2 arg3 "non space separated arg" 'arg with a quote " ']]
  4. local args = {}
  5.    
  6. local temp = ""
  7. local q = false
  8. line = line .. " "
  9. for char in line:gmatch("(.)") do
  10.     local write = false
  11.    
  12.     if
  13.         char == [[']] or
  14.         char == [["]]
  15.     then
  16.         if not q then
  17.             q = char
  18.             char = ""
  19.         elseif q == char then
  20.             q = false
  21.             write = true
  22.             char = ""
  23.         end
  24.     end
  25.    
  26.     if q then
  27.         temp = temp .. char
  28.     elseif char:find("%s") then
  29.         write = true
  30.         char = ""
  31.     else
  32.         temp = temp .. char
  33.     end
  34.    
  35.     if write and temp ~= "" then
  36.         table.insert(args, temp)
  37.         temp = ""
  38.     end
  39.    
  40. end
  41.  
  42. table.foreach(args, print)
Advertisement
Add Comment
Please, Sign In to add comment