xXm0dzXx

Untitled

May 16th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. local bExit = false
  2.  
  3. function eDecode(test)
  4. test = fs.open(test, "r")
  5. for i=1, *number of lines* do
  6. --Read each line and store it as tWords
  7.  
  8. for match in string.gmatch(sLine, "[^ \t]+") do
  9. table.insert( tWords, match )
  10. end
  11.  
  12. eBatch(tWords)
  13. end
  14. test.close()
  15. end
  16.  
  17. function eBatch(tWords)
  18. local sCommand = tWords[1]
  19. if sCommand == "echo" then
  20. print(tWords[2])
  21. elseif sCommand == "exit" then
  22. bExit = true
  23. elseif sCommand == "pause" then
  24. print("Press any key to continue.")
  25. os.pullEvent("key")
  26. sleep(0)
  27. elseif sCommand == "cls" then
  28. term.clear()
  29. term.setCursorPos(1,1)
  30. elseif sCommand == "del" then
  31. if tWords[2] then
  32. if fs.exists(tWords[2]) then
  33. if fs.isReadOnly(tWords[2]) then
  34. print("nul file")
  35. else
  36. fs.delete( tWords[2] )
  37. end
  38. end
  39. end
  40. elseif sCommand == "execute" then --just made this one up, might not exist
  41. if fs.exists(tWords[2]) then
  42. eDecode(tWords[2])
  43. else
  44. print("File does not exist.")
  45. end
  46. elseif sCommand == "title" then
  47. return tWords[2] --Title is pretty much useless here, so i'll just return what they typed for other's programs.
  48. else
  49. print("nul")
  50. end
  51. end
  52.  
  53. print("BATCH Simulator v0.1")
  54. print("Type 'exit' to exit")
  55.  
  56. local tCommandHistory = {}
  57. while not bExit do
  58. write( "BATCH_> " )
  59.  
  60. local sLine = read( nil, tCommandHistory )
  61. table.insert( tCommandHistory, sLine )
  62.  
  63. local tWords = {}
  64. for match in string.gmatch(sLine, "[^ \t]+") do
  65. table.insert( tWords, match )
  66. end
  67.  
  68. eBatch(tWords)
  69. end
Advertisement
Add Comment
Please, Sign In to add comment