Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- local funcs = {}
- local _print = print
- local _term_write = term.write
- local _term_clear = term.clear
- local _term_clearLine = term.clearLine
- local _term_scroll = term.scroll
- local _term_setCursorPos = term.setCursorPos
- local _io_write = io.write
- local _io_read = io.read
- local buf = {}
- local client
- function myWrite(s)
- buf[#buf+1]=s
- end
- function myRead()
- rednet.send(client,"\1read")
- local _,msg = rednet.receive()
- return msg
- end
- function myClear()
- rednet.send(client,"\1clear")
- end
- function myClearLine()
- rednet.send(client,"\1clearLine")
- end
- function myScroll()
- rednet.send(client,"\1scroll")
- end
- function mySetCursorPos(x,y)
- rednet.send(client,"\1setCursorPos"..x..","..y)
- end
- function hookIO()
- rawset(_G,"print",myWrite)
- rawset(_G["term"],"write",myWrite)
- rawset(_G["term"],"clear",myClear)
- rawset(_G["term"],"clearLine",myClearLine)
- rawset(_G["term"],"scroll",myScroll)
- rawset(_G["term"],"setCursorPos",mySetCursorPos)
- rawset(_G["io"],"write",myWrite)
- rawset(_G["io"],"read",myRead)
- end
- function unhookOutput()
- rawset(_G,"print",_print)
- rawset(_G["term"],"write",_term_write)
- rawset(_G["term"],"clear",_term_clear)
- rawset(_G["term"],"clearLine",_term_clearLine)
- rawset(_G["term"],"scroll",_term_scroll)
- rawset(_G["term"],"setCursorPos",_term_setCursorPos)
- rawset(_G["io"],"write",_io_write)
- rawset(_G["io"],"read",_io_read)
- end
- function funcs.exe(id,args)
- local t = {}
- if #args~=2 then
- for i=2,#args do
- t[i-1]=args[i]
- end
- else
- t[1]=args[2]
- end
- local run =
- function()
- shell.run(args[1],unpack(t))
- end
- local reader =
- function()
- while #buf~=0 do
- rednet.send(id,buf[1])
- table.remove(buf,1)
- end
- end
- client = id
- hookIO()
- run()
- unhookIO()
- reader()
- rednet.send(id,"\1done")
- end
- function process(id,msg)
- local rest = string.gmatch(msg,"cmd:(.+)$")()
- local func,args = string.gmatch(rest,"^(.-):(.+)$")()
- local t = {}
- for v in string.gmatch(args,"[^:]+") do
- t[#t+1]=v
- end
- funcs[func](id,t)
- end
- while true do
- local id,msg = rednet.receive()
- if msg:sub(1,4) == "cmd:" then
- process(id,msg)
- end
- end
- rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment