Difference between revisions of "Term.redirect"
From ComputerCraft Wiki
(Fixed return value) |
Bomb Bloke (Talk | contribs) (More details.) |
||
Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=term.redirect | |name=term.redirect | ||
+ | |args={{type|table}} terminal object | ||
|returns={{type|table}} previous terminal object | |returns={{type|table}} previous terminal object | ||
|api=term | |api=term | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc=Redirects terminal output to a monitor ( | + | |desc=Redirects [[term (API)|terminal]] output to a [[monitor]], a [[window (API)|window]], or any custom terminal object. Once the redirect is performed, any calls to a "term" function - or to a function that makes ''use'' of a term function, as as [[print|print()]] - will instead operate with the new terminal object. |
+ | |||
+ | A "terminal object" is simply a table that contains functions with the same names - and general features - as those found in the [[term (API)|term]] table. For example, a [[Peripheral.wrap|wrapped]] monitor is suitable. | ||
+ | |||
+ | The redirect can be undone by pointing back to [[term.native|term.native()]] (or, for ComputerCraft builds older than 1.6, using [[term.restore|term.restore()]]). | ||
+ | |||
|examples= | |examples= | ||
{{Example | {{Example | ||
|desc=Prints "Hello World!" on the right monitor. | |desc=Prints "Hello World!" on the right monitor. | ||
|code=term.redirect(peripheral.wrap("right"))<br>print("Hello World!") | |code=term.redirect(peripheral.wrap("right"))<br>print("Hello World!") | ||
− | | | + | }} |
+ | {{Example | ||
+ | |desc=Restores terminal functionality back to the default display (users of ComputerCraft builds older than 1.6 should use [[term.restore|term.restore()]] instead). | ||
+ | |code=term.redirect(term.native()) | ||
}} | }} | ||
}} | }} | ||
[[Category:API_Functions]] | [[Category:API_Functions]] |
Revision as of 13:04, 17 December 2014
Function term.redirect | |
Redirects terminal output to a monitor, a window, or any custom terminal object. Once the redirect is performed, any calls to a "term" function - or to a function that makes use of a term function, as as print() - will instead operate with the new terminal object.
A "terminal object" is simply a table that contains functions with the same names - and general features - as those found in the term table. For example, a wrapped monitor is suitable. The redirect can be undone by pointing back to term.native() (or, for ComputerCraft builds older than 1.6, using term.restore()). | |
Syntax | term.redirect(table terminal object) |
Returns | table previous terminal object |
Part of | ComputerCraft |
API | term |
Examples
Example | |
Prints "Hello World!" on the right monitor. | |
Code |
term.redirect(peripheral.wrap("right")) |
Example | |
Restores terminal functionality back to the default display (users of ComputerCraft builds older than 1.6 should use term.restore() instead). | |
Code |
term.redirect(term.native()) |