SHOW:
|
|
- or go back to the newest paste.
| 1 | rednet.open("right")
| |
| 2 | ||
| 3 | local client | |
| 4 | function myWrite(...) | |
| 5 | rednet.send(client,write) | |
| 6 | rednet.send(client,table.concat({...}," "))
| |
| 7 | end | |
| 8 | - | function rednetTarget(id) |
| 8 | + | |
| 9 | - | client = id |
| 9 | + | |
| 10 | local rProg = shell.resolveProgram(prog) | |
| 11 | - | return |
| 11 | + | |
| 12 | - | {
|
| 12 | + | local env = { term= { write = myWrite, }, print = myWrite,}
|
| 13 | - | write=function(...) paralell.waitForAll(,) end |
| 13 | + | |
| 14 | - | getSize = term.getSize |
| 14 | + | for k,v in pairs(_G) do |
| 15 | - | } |
| 15 | + | if type(k)=="string" and type(v)=="table" then |
| 16 | env[k] = v | |
| 17 | end | |
| 18 | - | term.redirect(rednetTarget(id)) |
| 18 | + | |
| 19 | - | local ret = shell.run(prog,...) |
| 19 | + | |
| 20 | - | term.restore() |
| 20 | + | env.shell=shell |
| 21 | ||
| 22 | local f,err = loadfile( rProg ) | |
| 23 | if f then | |
| 24 | setfenv(f,env) | |
| 25 | local args={...}
| |
| 26 | local ret,err = pcall(function() f(unpack(args)) end) | |
| 27 | if not ok then | |
| 28 | if err and err~="" then | |
| 29 | error(err,1) | |
| 30 | end | |
| 31 | end | |
| 32 | end | |
| 33 | ||
| 34 | if err and err~="" then | |
| 35 | error(err,1) | |
| 36 | end | |
| 37 | ||
| 38 | return ret | |
| 39 | end | |
| 40 | ||
| 41 | function split(s) | |
| 42 | local t = {}
| |
| 43 | for v in string.gmatch(s,"[^%s]+") do | |
| 44 | t[#t+1]=v | |
| 45 | end | |
| 46 | return t | |
| 47 | end | |
| 48 | ||
| 49 | while true do | |
| 50 | local id,msg = rednet.receive() | |
| 51 | local cmd,args=string.gmatch(msg,"(.-) (.*)$")() | |
| 52 | print("'"..args.."' "..id)
| |
| 53 | if args then | |
| 54 | args=split(args) | |
| 55 | print(args[1]) | |
| 56 | ret = run(id,cmd,unpack(args)) | |
| 57 | else | |
| 58 | ret = run(id,cmd) | |
| 59 | end | |
| 60 | rednet.send(id,tostring(ret)) | |
| 61 | rednet.send(id,"end") | |
| 62 | end | |
| 63 | ||
| 64 | ||
| 65 | rednet.close("right") |