Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load the Rednet API
- rednet.open("left")
- function captureOutput(func, ...)
- local oldTerm = term.redirect(term.native())
- local filter = function() return true end
- local co = coroutine.create(func)
- local function resume(...)
- local ok, event = coroutine.resume(co, ...)
- if not ok then
- error(event, 0)
- end
- return event
- end
- resume(...) -- Initial call to start the coroutine
- while coroutine.status(co) ~= 'dead' do
- local eventData = {os.pullEvent()}
- if eventData[1] == "char" or eventData[1] == "key" then
- -- We ignore keypresses to the terminal
- else
- -- Send non-keypress terminal data to the computer
- if eventData[1] == "print" then
- rednet.send(computer_id, table.concat(eventData, ", ", 2))
- end
- resume(unpack(eventData))
- end
- end
- term.redirect(oldTerm)
- end
- -- Infinite loop to listen for commands
- while true do
- local id, command = rednet.receive()
- if command:find("excavate ") then
- computer_id = id -- Remember the computer's ID
- local size = command:gsub("excavate ", "")
- captureOutput(function() shell.run(command) end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement