Jump to content




How to move the term stack backwards?


4 replies to this topic

#1 Axiom

  • Members
  • 6 posts

Posted 10 June 2017 - 09:58 PM

Hello :). I was wondering how to move the term stack backwards. I apologize if this has already been asked, I didn't know how to search for this specific question haha. I know that term.redirect will add another term object to the stack, but then how do you remove it? Also I think that you can do something like:

term = term.native()

But I wasn't sure if this is the intended way of resetting term. I think what I'm looking for is something similar to the old term.restore, from what I can tell on the wiki. If you have any guidance it would be much appreciated, thank you in advance! :).

#2 Bomb Bloke

    Hobbyist Coder

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

Posted 10 June 2017 - 11:37 PM

There is no stack, not since term.restore() was removed from the mod. term.redirect() returns the previous terminal object, allowing this simple construct:

local oldTerm = term.redirect(newTerm)

.
.
.

term.redirect(oldTerm)

Never assume your script "started off" using term.native().

Edited by Bomb Bloke, 10 June 2017 - 11:38 PM.


#3 Axiom

  • Members
  • 6 posts

Posted 11 June 2017 - 02:11 AM

 Bomb Bloke, on 10 June 2017 - 11:37 PM, said:

There is no stack, not since term.restore() was removed from the mod. term.redirect() returns the previous terminal object, allowing this simple construct:
local oldTerm = term.redirect(newTerm)
.
.
.
term.redirect(oldTerm)
Never assume your script "started off" using term.native().
Oh, I see now, thank you! :)

If you don't mind, I'm still wondering about something. On the wiki it states that term.native, term.current, and term.redirect are only available on the base term object. I'm unsure what this means as it would only make sense for these functions to be available regardless of what term object is being used. Does this mean that any term object passed to term.redirect need not implement these methods as they will be automatically inherited from the base term object? Sorry for the follow up question, thank you for your help so far! :)

Edit: And, if these methods aren't automatically inherited, how would term.redirect be implemented if someone were to make a custom term object?

Edited by Axiom, 11 June 2017 - 02:45 AM.


#4 Bomb Bloke

    Hobbyist Coder

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

Posted 11 June 2017 - 06:11 AM

Consider a "terminal object" to be a table container function pointers for the purpose of dealing with a given display, and "term" to be a table containing function pointers for the purpose of dealing with a given terminal object. It's a wrapper system.

When a computer boots, the "term" API initially available is filled with pointers for native Lua functions (defined by ComputerCraft's Java-side code - there's no Lua source for them) that act directly upon that computer's display. Then this gets loaded, replacing that original API with itself and making the old copy available via term.native(). The redirect / current / native function pointers don't exist within the native terminal object, but rather are additions to the new "term" API.

When you term.redirect() to a different terminal object, the "term" table doesn't actually change, and nor are the functions within it replaced. Rather, the same functions that the "term" table already pointed to will start calling the new terminal object's functions for you. So your object isn't inheriting anything - rather, it's the other way around: "term" inherits what it needs from your object, and it only needs to inherit the bits that "act on a display".

#5 Axiom

  • Members
  • 6 posts

Posted 11 June 2017 - 01:32 PM

Ahh, thank you for explaining it very clearly! :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users