Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Programming Environment")
- print("Commands: 'run <file>', 'save <file>', 'load <file>', 'exit'")
- while true do
- write("> ")
- local input = read()
- local command, arg = string.match(input, "^(%S+)%s*(.*)$")
- if command == "run" and arg then
- if fs.exists(arg) then
- local success, err = pcall(function() shell.run(arg) end)
- if not success then
- print("Error: " .. err)
- local log = fs.open("/error_log.txt", "a")
- log.writeLine("Error while running " .. arg .. ": " .. err)
- log.close()
- end
- else
- print("File not found.")
- end
- elseif command == "save" and arg then
- write("Enter your code. Type 'end' to finish.")
- local code = ""
- while true do
- local line = read()
- if line == "end" then break end
- code = code .. line .. "\n"
- end
- local file = fs.open(arg, "w")
- file.write(code)
- file.close()
- print("File saved as " .. arg)
- elseif command == "load" and arg then
- if fs.exists(arg) then
- local file = fs.open(arg, "r")
- print(file.readAll())
- file.close()
- else
- print("File not found.")
- end
- elseif command == "exit" then
- break
- else
- print("Invalid command.")
- end
- end
Add Comment
Please, Sign In to add comment