This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DevelopedLogic's profile picture

OS API Overriding

Started by DevelopedLogic, 02 July 2017 - 04:39 AM
DevelopedLogic #1
Posted 02 July 2017 - 06:39 AM
Hello,

I'm building an OS, and I'm implementing out-of-the-box multi-display support. The issue I have is all programs written for CC do not use the display API which I have written to do this multi-display support.

I have tried to work around this, by loading my Display API into the programs at the very beginning as term.lua (I tried this with Redirection) but it just isn't working.

Here is my code: https://pastebin.com/JS7FsH1F

All I basically need to do is override the term API in a specific program, whilst retaining the term API in the Display API.

When I load the API, the computer just waits a moment then shuts down. I don't know what the issue is. Please help! :)/>
Bomb Bloke #2
Posted 02 July 2017 - 07:54 AM
Don't try to replace the main "term" table. Instead, create a table with the same functions as the one term.native() gives you, and then pass that to term.redirect().
DevelopedLogic #3
Posted 02 July 2017 - 08:14 AM
Don't try to replace the main "term" table. Instead, create a table with the same functions as the one term.native() gives you, and then pass that to term.redirect().

Looking at the code I have written, I have included all of the functions that the normal term API has included. Does this mean I can simply redirect to my display API already?

Edit: I tried to run Redirection after redirecting to my API, but the computer just shut down again.

Edit2: Before the computer shuts down it pops up an error briefly in white text, I caught the word reinstall, but it blinked away too fast.
Edited on 02 July 2017 - 06:39 AM
Bomb Bloke #4
Posted 03 July 2017 - 07:31 AM
Looking at your code, you've got some recursion issues. Most of your functions start out by calling themselves, and the resulting loops will indeed lead to a shutdown.

If you want your terminal object to output to the previous terminal object (in addition to your monitors), then the idea is to first make copies of the function pointers in the table term.current() gives you before you start construction of your own object:

local oldClear = term.current().clear

function clear()
  oldClear()
  .
  .
  .

However, you truly don't need to manually define each function one after the other; it's possible to do it all within a short loop.
DevelopedLogic #5
Posted 03 July 2017 - 07:55 PM
Looking at your code, you've got some recursion issues. Most of your functions start out by calling themselves, and the resulting loops will indeed lead to a shutdown.

If you want your terminal object to output to the previous terminal object (in addition to your monitors), then the idea is to first make copies of the function pointers in the table term.current() gives you before you start construction of your own object:

local oldClear = term.current().clear

function clear()
  oldClear()
  .
  .
  .

However, you truly don't need to manually define each function one after the other; it's possible to do it all within a short loop.

ITS ALIVE!!!! Thank you for the help! I made it so the term calls referred to the native terminal. I fully understand where I went wrong now, as when I redirect I loop back on myself. Great. New code is at the same pastebin link.

I prefer to make the API with all of the functions defined to allow for maximum changes in the future.

You have saved my OS, thanks!