Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bExit = false
- function eDecode(test)
- test = fs.open(test, "r")
- for i=1, *number of lines* do
- --Read each line and store it as tWords
- for match in string.gmatch(sLine, "[^ \t]+") do
- table.insert( tWords, match )
- end
- eBatch(tWords)
- end
- test.close()
- end
- function eBatch(tWords)
- local sCommand = tWords[1]
- if sCommand == "echo" then
- print(tWords[2])
- elseif sCommand == "exit" then
- bExit = true
- elseif sCommand == "pause" then
- print("Press any key to continue.")
- os.pullEvent("key")
- sleep(0)
- elseif sCommand == "cls" then
- term.clear()
- term.setCursorPos(1,1)
- elseif sCommand == "del" then
- if tWords[2] then
- if fs.exists(tWords[2]) then
- if fs.isReadOnly(tWords[2]) then
- print("nul file")
- else
- fs.delete( tWords[2] )
- end
- end
- end
- elseif sCommand == "execute" then --just made this one up, might not exist
- if fs.exists(tWords[2]) then
- eDecode(tWords[2])
- else
- print("File does not exist.")
- end
- elseif sCommand == "title" then
- return tWords[2] --Title is pretty much useless here, so i'll just return what they typed for other's programs.
- else
- print("nul")
- end
- end
- print("BATCH Simulator v0.1")
- print("Type 'exit' to exit")
- local tCommandHistory = {}
- while not bExit do
- write( "BATCH_> " )
- local sLine = read( nil, tCommandHistory )
- table.insert( tCommandHistory, sLine )
- local tWords = {}
- for match in string.gmatch(sLine, "[^ \t]+") do
- table.insert( tWords, match )
- end
- eBatch(tWords)
- end
Advertisement
Add Comment
Please, Sign In to add comment