yeeeeeeeeeeeee

part 4

Mar 20th, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. print("Programming Environment")
  2. print("Commands: 'run <file>', 'save <file>', 'load <file>', 'exit'")
  3. while true do
  4.     write("> ")
  5.     local input = read()
  6.     local command, arg = string.match(input, "^(%S+)%s*(.*)$")
  7.     if command == "run" and arg then
  8.         if fs.exists(arg) then
  9.             local success, err = pcall(function() shell.run(arg) end)
  10.             if not success then
  11.                 print("Error: " .. err)
  12.                 local log = fs.open("/error_log.txt", "a")
  13.                 log.writeLine("Error while running " .. arg .. ": " .. err)
  14.                 log.close()
  15.             end
  16.         else
  17.             print("File not found.")
  18.         end
  19.     elseif command == "save" and arg then
  20.         write("Enter your code. Type 'end' to finish.")
  21.         local code = ""
  22.         while true do
  23.             local line = read()
  24.             if line == "end" then break end
  25.             code = code .. line .. "\n"
  26.         end
  27.         local file = fs.open(arg, "w")
  28.         file.write(code)
  29.         file.close()
  30.         print("File saved as " .. arg)
  31.     elseif command == "load" and arg then
  32.         if fs.exists(arg) then
  33.             local file = fs.open(arg, "r")
  34.             print(file.readAll())
  35.             file.close()
  36.         else
  37.             print("File not found.")
  38.         end
  39.     elseif command == "exit" then
  40.         break
  41.     else
  42.         print("Invalid command.")
  43.     end
  44. end
  45.  
Add Comment
Please, Sign In to add comment