caucow

ctrlterm

Dec 28th, 2016 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. multishell.setTitle(multishell.getCurrent(), "term")
  2. local m = peripheral.find("modem")
  3. local senderID = os.getComputerLabel() == nil and "ID:" .. os.getComputerID() or os.getComputerLabel()
  4. local channels = {
  5.       ["stdout"] = 1000,
  6.       ["stdin"] = 1001,
  7.       ["witherout"] = 1010,
  8.       ["witherin"] = 1011
  9.     }
  10.  
  11. local function sendCmd(program, cmd, ...)
  12.   m.transmit(channels.stdin, channels.stdout,
  13.       {
  14.           ["program"] = program,
  15.           ["type"] = "cmd",
  16.           ["cmd"] = cmd,
  17.           ["text"] = {...},
  18.           ["sender"] = senderID
  19.       })
  20. end
  21.  
  22. function split(inputstr, sep)
  23.   if sep == nil then
  24.     sep = "%s"
  25.   end
  26.   local t={} ; i=1
  27.   for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  28.     t[i] = str
  29.     i = i + 1
  30.   end
  31.   return t
  32. end
  33.  
  34. while true do
  35.   sendCmd("control", unpack(split(read())))
  36. end
Add Comment
Please, Sign In to add comment