Please explain me, how is new term redirection system supposed to work?
1. I can't find any analogue for term.restore. term table itself "is not recommended redirect target", term.native is "do-not-use-unless-you-have-to" function, term.redirect(nil) is forbidden. What should I do?
2. I noticed that when a program that called term.redirect stops, it restores automatically (but the error message, if it exists, is sent to monitor).
2.1. Please, show me that piece of code that changes redirect targets back. I can't find it.
2.2. How i can prevent this thing from happening?
Terminal redirection questions
Started by 0099, Jul 07 2014 06:55 PM
7 replies to this topic
#1
Posted 07 July 2014 - 06:55 PM
#2
Posted 07 July 2014 - 07:09 PM
0099, on 07 July 2014 - 06:55 PM, said:
Please explain me, how is new term redirection system supposed to work?
1. I can't find any analogue for term.restore. term table itself "is not recommended redirect target", term.native is "do-not-use-unless-you-have-to" function, term.redirect(nil) is forbidden. What should I do?
2. I noticed that when a program that called term.redirect stops, it restores automatically (but the error message, if it exists, is sent to monitor).
2.1. Please, show me that piece of code that changes redirect targets back. I can't find it.
2.2. How i can prevent this thing from happening?
1. I can't find any analogue for term.restore. term table itself "is not recommended redirect target", term.native is "do-not-use-unless-you-have-to" function, term.redirect(nil) is forbidden. What should I do?
2. I noticed that when a program that called term.redirect stops, it restores automatically (but the error message, if it exists, is sent to monitor).
2.1. Please, show me that piece of code that changes redirect targets back. I can't find it.
2.2. How i can prevent this thing from happening?
local monitor = peripheral.wrap("left")
local oldTerm = term.redirect(monitor)
--# code here
term.redirect(oldTerm)
it has been this way since 1.6x
Edited by theoriginalbit, 07 July 2014 - 07:24 PM.
oops. thanks Lyqyd.
#3
Posted 07 July 2014 - 07:23 PM
You swapped redirect for restore in your response, theoriginalbit.
Edit: Also, this is compatible with both pre- and post-1.6:
Edit: Also, this is compatible with both pre- and post-1.6:
local _old = term.redirect(target) --# code here if _old then term.redirect(_old) else term.restore() end
#4
Posted 08 July 2014 - 03:46 PM
Thanks. But what about the automatical restoring - what if I don't like it?
I mean, I could write a small program to redirect output:
And I still can't find - where exactly does this happen?
I mean, I could write a small program to redirect output:
-- file name: "redir"
local tArgs = { ... }
assert(type(tArgs[1]) == "string", "Usage: redir (side)")
term.redirect(peripheral.wrap(tArgs[1]))
It won't work.And I still can't find - where exactly does this happen?
#5
Posted 08 July 2014 - 03:54 PM
There is no 'automatic restoring' using your code example you would do the following
local args = {...}
assert(type(args[1]) == "string", "Usage: redir (side)")
--# anything printed here will output to whatever the term object was before your program started (normally this is the computer)
local oldTerm = term.redirect(peripheral.wrap(args[1]))
--# everything printed here will output to the wrapped peripheral
term.redirect( oldTerm )
--# everything printed here will print back on the term object that was active when your program started
#6
Posted 10 July 2014 - 02:37 PM
theoriginalbit, on 08 July 2014 - 03:54 PM, said:
There is no 'automatic restoring' using your code example you would do the following
(code here)
(code here)
P.S. My original question was in beta discussion, so I tested all this in 1.64pr2. 1.64 is where I need it, because term.restore is gone. I'll test it in an earlier version.
EDIT: Tested it in 1.63 and got the same result.
Edited by 0099, 10 July 2014 - 02:41 PM.
#7
Posted 10 July 2014 - 02:53 PM
Are you testing on an advanced computer or a normal one? The multishell program may be part of the reason you're seeing redirection after a program exits.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











