Jump to content




Environments, windows


  • You cannot reply to this topic
6 replies to this topic

#1 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 28 September 2016 - 08:47 PM

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

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 28 September 2016 - 09:18 PM

View PostKingofGamesYami, 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})
and
term.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 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 September 2016 - 10:01 PM

Actually (...) is/are vararg(s).

#5 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 29 September 2016 - 11:09 AM

varargs, okay.
Why textutils respect the current term in the environment in this case?

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#7 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 29 September 2016 - 05:40 PM

View PostBomb 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.

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