Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.find "modem"
- local log_channel, job_channel = 404, 1337
- m.open(log_channel)
- local function randbytes(len)
- local out = ""
- for i = 1, len do
- out = out .. string.char(math.random(1, 255))
- end
- return out
- end
- local function fread(n)
- local f = fs.open(n, "r")
- local c = f.readAll()
- f.close()
- return c
- end
- local function run(text, title)
- local done_sending = false
- local done_printing = false
- local function recv()
- while not done_printing do
- local _, _, chan, reply_chan, message = os.pullEvent "modem_message"
- if chan == log_channel and reply_chan == job_channel then
- if type(message) == "string" then print(message) end
- if type(message) == "table" and message.type then
- local mtype = message.type
- if mtype == "job_starting" then done_sending = true end
- if mtype == "job_complete" then done_printing = true end
- end
- end
- end
- end
- local function send()
- while not done_sending do
- m.transmit(job_channel, log_channel, {text = text, title = title})
- sleep(2)
- end
- end
- parallel.waitForAll(send, recv)
- end
- if shell.getRunningProgram() == "print" then
- local filename, title = ...
- local text = fread(filename)
- title = title or randbytes(8)
- run(text, title)
- else
- return run
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement