Advertisement
Freack100

Poop Interpreter

Jul 23rd, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. local chars = "0123456789abcdefghijklmnopqrstuvwxyz.,-!?+*<>#@$ۤ%&/()[]"
  2. local msg = ""
  3. local pointer = 1
  4. local commands = {
  5.     ["eat"] = function()
  6.         pointer = pointer+1
  7.         if(pointer > #chars) then pointer = 1 end
  8.     end,
  9.     ["puke"] = function()
  10.         pointer = pointer-1
  11.         if(pointer < 1) then pointer = #chars end
  12.     end,
  13.     ["poop"] = function()
  14.         msg = msg..chars:sub(pointer,pointer)
  15.     end,
  16.     ["POOP"] = function()
  17.         msg = msg..chars:sub(pointer,pointer):upper()
  18.     end,
  19.     ["sniff"] = function()
  20.         write(msg.." ")
  21.     end,
  22.     ["flush"] = function()
  23.         msg = ""
  24.         pointer = 1
  25.     end
  26. }
  27.  
  28. local args = {...}
  29. if(#args < 1) then error("I need more arguments.",0) end
  30. if(not fs.exists(args[1])) then error("File not found",0) end
  31.  
  32. local handle = fs.open(args[1],"r")
  33. local content = handle.readAll()
  34. handle.close()
  35.  
  36. content = content:gsub("\n"," ")
  37.  
  38. for word in content:gmatch("[^ \t]+") do
  39.     commands[word]()
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement