Hey guys,
i'm not sure about this:
If i create a window and start a program with an environment: setmetatable({term = window}, {<index point to _G>}),
would all APIs like textutils use the term of the programs environment or the term of the global table.
I did a test, and textutils respects the window, but in my second test, the program only get term as a window and textutils, without sleep and it also works.
Inherit textutils all fields of the upper program caller or use it the global term or is there a secret mechanism?
Thanks in advance and hopefully it inherits all fields of the upper program
Sewbacca
Environments, windows
Started by Sewbacca, Sep 28 2016 08:47 PM
6 replies to this topic
#1
Posted 28 September 2016 - 08:47 PM
#2
Posted 28 September 2016 - 09:05 PM
textutils respects term.redirects. Don't even bother inserting term into the environment, just use term.redirect. You might replace term.native() though.
#3
Posted 28 September 2016 - 09:18 PM
KingofGamesYami, on 28 September 2016 - 09:05 PM, said:
textutils respects term.redirects. Don't even bother inserting term into the environment, just use term.redirect. You might replace term.native() though.
I used:
loadfile('test', {term = window.create(...), textutils = textutils})
andterm.write(...) textutils.slowPrint(...)and it works.
... stands for data, i am to lazy to write it down, not for closures (i'm not sure, if this is the right name)
Edited by Sewbacca, 28 September 2016 - 09:32 PM.
#4
Posted 28 September 2016 - 10:01 PM
Actually (...) is/are vararg(s).
#5
Posted 29 September 2016 - 11:09 AM
varargs, okay.
Why textutils respect the current term in the environment in this case?
Why textutils respect the current term in the environment in this case?
#6
Posted 29 September 2016 - 11:31 AM
Because textutils doesn't specifically index into _G to get the default term table.
It needs to, though, and a window object won't cut the mustard as a replacement - any script which wants to call term.native(), term.current(), term.redirect(), etc will fail the way you're doing things because windows don't offer those functions.
So: use term.redirect() yourself. If you want to use a specific terminal when calling a function, redirect to that terminal before calling that function. If you want to associate a terminal with a coroutine, redirect before each resume, and pay attention to what it might've switched to when it next yields.
It needs to, though, and a window object won't cut the mustard as a replacement - any script which wants to call term.native(), term.current(), term.redirect(), etc will fail the way you're doing things because windows don't offer those functions.
So: use term.redirect() yourself. If you want to use a specific terminal when calling a function, redirect to that terminal before calling that function. If you want to associate a terminal with a coroutine, redirect before each resume, and pay attention to what it might've switched to when it next yields.
#7
Posted 29 September 2016 - 05:40 PM
Bomb Bloke, on 29 September 2016 - 11:31 AM, said:
Because textutils doesn't specifically index into _G to get the default term table.
It needs to, though, and a window object won't cut the mustard as a replacement - any script which wants to call term.native(), term.current(), term.redirect(), etc will fail the way you're doing things because windows don't offer those functions.
So: use term.redirect() yourself. If you want to use a specific terminal when calling a function, redirect to that terminal before calling that function. If you want to associate a terminal with a coroutine, redirect before each resume, and pay attention to what it might've switched to when it next yields.
It needs to, though, and a window object won't cut the mustard as a replacement - any script which wants to call term.native(), term.current(), term.redirect(), etc will fail the way you're doing things because windows don't offer those functions.
So: use term.redirect() yourself. If you want to use a specific terminal when calling a function, redirect to that terminal before calling that function. If you want to associate a terminal with a coroutine, redirect before each resume, and pay attention to what it might've switched to when it next yields.
I think there are many reason, why window.create don't offers redirect, current and native methods.
Yes, i agree with you using term.redirect. I had many ideas, by setting up an environment with
term = window.create(...), but there are too many ways to hack you out of the given term. The easiest
version i think, is using an API.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











