Advertisement
Guest User

CasavaNet.lua

a guest
Jan 23rd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. --if not os.getComputerLabel() then
  2. --  local label = "casavanet_" .. tostring(math.random(1000000, 999999))
  3. --  os.setComputerLabel(label)
  4. --  print("Set label to", label)
  5. --end
  6.  
  7. print("CasavaNet 1.0")
  8. local modem = peripheral.find("modem")
  9. modem.open(9191)
  10. local cordinate = nil
  11. local w, h = term.getSize()
  12. local running = false
  13.  
  14. while true do
  15.   local e = {os.pullEvent()}
  16.   if e[1] == "modem_message" then
  17.     local msg = e[5]
  18.  
  19.     if msg.type == "shutdown" then
  20.       print("Shutting down...")
  21.       sleep(0.5)
  22.       os.shutdown()
  23.     elseif msg.type == "start" then
  24.       running = true
  25.       print("Starting new program")
  26.       local function run()
  27.         print("Running", table.unpack(msg.content))
  28.         shell.run(table.unpack(msg.content))
  29.       end
  30.       cor = coroutine.create(run)
  31.       win = window.create(term.native(), 1, 1, w, h)
  32.     elseif msg.type == "end" then
  33.       running = false
  34.       print("Ending program")
  35.       cor = nil
  36.       win = nil
  37.     elseif msg.type == "event" and running and cor and window then
  38.       local data = msg.content
  39.       term.redirect(win)
  40.       coroutine.resume(cor, unpack(data))
  41.     end
  42.   end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement