Advertisement
Kar27

testterm.lua

Apr 30th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. -- Meant to be ran on Resolution 80; 25
  2. local term = require("term")
  3. local process = require("process")
  4. local shell = require("shell")
  5.  
  6. function shallowcopy(orig) --To copy tables
  7.     local orig_type = type(orig)
  8.     local copy
  9.     if orig_type == 'table' then
  10.         copy = {}
  11.         for orig_key, orig_value in pairs(orig) do
  12.             copy[orig_key] = orig_value
  13.         end
  14.     else
  15.         copy = orig
  16.     end
  17.     return copy
  18. end
  19.  
  20. function cusenv(newenv)
  21.     setmetatable(newenv, { __index = env })
  22.     --return newenv --It is probably for the good to keep it not working
  23. end
  24.  
  25. local co1 = process.load("testing.lua", cusenv({ --Init our program 1
  26.     msg = "Testing 1"
  27. }))
  28. local co2 = process.load("testing.lua", cusenv({ --Init our program 1
  29.     msg = "Testing 2"
  30. }))
  31. local enforcments = {}
  32. enforcments[co1] = { -- Program 1 window width and heigth setup (Left half of the screen)
  33.     w = 40,
  34.     h = 20
  35. }
  36. enforcments[co2] = { -- Program 1 window offset, width and heigth setup (Rigth half of the screen)
  37.     w = 40,
  38.     h = 20,
  39.     dx = 40,
  40. }
  41. -- Let's copy our main window
  42. process.list[co1].data.window = shallowcopy(term.internal.window())
  43. process.list[co2].data.window = shallowcopy(term.internal.window())
  44. while true do
  45.     for k, v in pairs(enforcments)  --Enforce window parameter enforcements
  46.         for k2, v2 in pairs(v) do
  47.             if process.list[k] then
  48.                 process.list[k].data.window[k2] = v2
  49.             end
  50.         end
  51.     end
  52.     for k, v in pairs(process.list) do --Execute coroutines
  53.         coroutine.resume(k)
  54.     end
  55.     os.sleep(0.2) -- Slow down execution
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement