Jump to content




Sync API - Terminal-Monitor Synchronization

api

29 replies to this topic

#1 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 20 September 2012 - 10:01 PM

This api lets you use all the screens you want at the same time. You can have the output on the console and all the monitors you want at the same time. It also supports custom output targets, in case you want to send the output through rednet or something like that.

The usage is really simple:
Spoiler

Example usage:
Spoiler

Download: pastebin (KhyGwUPm)
Code:
Spoiler

If you found any bugs, let me know so I can fix them.
Any feddback is appreciated.

Changelog:
- 11/3/2013: updated for CC 1.5, added color supprt
- 20/9/2012: first release

#2 SilverSatin

  • Members
  • 10 posts

Posted 25 September 2012 - 07:53 PM

This is by far my favorite code on the forum! I needed this so bad. Thanks A LOT !

i registered on the forum just to thank you!

#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 25 September 2012 - 09:49 PM

View PostSilverSatin, on 25 September 2012 - 07:53 PM, said:

This is by far my favorite code on the forum! I needed this so bad. Thanks A LOT !

i registered on the forum just to thank you!
Thanks :D/>
I wrote this just for testing, and then turned it into an api. It took just an hour :P/>
Any suggestions are welcome. If you'd like some feature to be added, just tell me and I'll try to do it.

#4 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 25 September 2012 - 10:12 PM

Ever since Espen started something like this, I've been looking for a standalone version, so thanks! Do you mind if I include this in my Operating System? Credit will of course be given as usual. Thanks for this API anyway :P/>

#5 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 25 September 2012 - 10:31 PM

View Posttoxicwolf, on 25 September 2012 - 10:12 PM, said:

Ever since Espen started something like this, I've been looking for a standalone version, so thanks! Do you mind if I include this in my Operating System? Credit will of course be given as usual. Thanks for this API anyway :D/>
Sure, no problem. Hope to see WolfOS 1.4 soon :P/>

#6 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 26 September 2012 - 06:06 AM

View PostMysticT, on 25 September 2012 - 10:31 PM, said:

View Posttoxicwolf, on 25 September 2012 - 10:12 PM, said:

Ever since Espen started something like this, I've been looking for a standalone version, so thanks! Do you mind if I include this in my Operating System? Credit will of course be given as usual. Thanks for this API anyway :D/>
Sure, no problem. Hope to see WolfOS 1.4 soon :P/>
Thanks :)/> And I hope so too, but I have so much to do and so little time!

#7 stilldabomb

  • New Members
  • 110 posts

Posted 26 September 2012 - 06:13 AM

Haha, this is awesome MysticT! Great job!

#8 juiceblox

  • New Members
  • 12 posts

Posted 30 September 2012 - 07:00 PM

Ok, I'm learning here. I'm hoping I can get some explanations. I have the API working beautifully, but I am curious.

1. What is the first part of the API code doing?
2. When you call a function that's in an API file, does it not just read the part of the code where the function is defined, or does it go through the entire API file?
3. What's the point of putting the term local before a function?
4. What does sync.redirect do? The example shows an input of true (to set default target as default?) and the function sets the input, true, as variable bAddterm to be wierdly used in an if statement? This whole function confuses me.
5. What is target?

#9 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 30 September 2012 - 07:14 PM

1. What is the first part of the API code doing?
- It defines some needed variables and functions to use later in the api.

2. When you call a function that's in an API file, does it not just read the part of the code where the function is defined, or does it go through the entire API file?
- When you use os.loadAPI (or put it in "rom/apis" to load it automatically), the whole file is loaded and the global functions and variables are saved in a table named like the api file (in this case sync).

3. What's the point of putting the term local before a function?
- It makes the function local to the api, so it can't be used from outside (for example, you can't use sync.resize because it's a local function).

4. What does sync.redirect do? The example shows an input of true (to set default target as default?) and the function sets the input, true, as variable bAddterm to be wierdly used in an if statement? This whole function confuses me.
- It redirects the terminal output (using term.redirect) to the table I defined with all the sync functions. The parameter just tells it whether the terminal/console should be added to the output targets.

5. What is target?
- It must be a table containing all the terminal functions (getSize, getCursorPos, setCursorPos, setCursorBlink, clear, clearLine, write and scroll).

#10 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 30 September 2012 - 08:10 PM

Not sure if this is an error on my behalf or not, but I've been having trouble getting the Sync API to work.

When I follow the example usage, trying to add the first monitor causes the computer to shutdown without an error message. Trying to add the monitor to the target list before the sync.redirect(true) call throws the following error:
sync:33: Invalid monitor setup
Hope you can help me :)/>

#11 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 30 September 2012 - 09:00 PM

View Posttoxicwolf, on 30 September 2012 - 08:10 PM, said:

Not sure if this is an error on my behalf or not, but I've been having trouble getting the Sync API to work.

When I follow the example usage, trying to add the first monitor causes the computer to shutdown without an error message. Trying to add the monitor to the target list before the sync.redirect(true) call throws the following error:
sync:33: Invalid monitor setup
Hope you can help me :)/>
Well, there's nothing I can do about it. It's been reported before as a bug, not sure what causes it, but I think it has something to do with chunk boundaries, so try moving the monitor so it's inside the same chunk.
Have you tried using the monitor without the api?

#12 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 01 October 2012 - 04:09 PM

View PostMysticT, on 30 September 2012 - 09:00 PM, said:

View Posttoxicwolf, on 30 September 2012 - 08:10 PM, said:

Not sure if this is an error on my behalf or not, but I've been having trouble getting the Sync API to work.

When I follow the example usage, trying to add the first monitor causes the computer to shutdown without an error message. Trying to add the monitor to the target list before the sync.redirect(true) call throws the following error:
sync:33: Invalid monitor setup
Hope you can help me :)/>
Well, there's nothing I can do about it. It's been reported before as a bug, not sure what causes it, but I think it has something to do with chunk boundaries, so try moving the monitor so it's inside the same chunk.
Have you tried using the monitor without the api?
Not sure why, but it all works fine now.. Perhaps updating to the latest Forge version and the CC 1.43pr1 helped in some way? Not sure exactly what I did different, but it now works.

#13 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 01 October 2012 - 04:24 PM

View Posttoxicwolf, on 01 October 2012 - 04:09 PM, said:

Not sure why, but it all works fine now.. Perhaps updating to the latest Forge version and the CC 1.43pr1 helped in some way? Not sure exactly what I did different, but it now works.

MAGIC

#14 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 12 October 2012 - 03:10 PM

Just to let you know, this doesn't work properly with the new CC v1.45 beta. It is missing the colour related functions.

#15 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 12 October 2012 - 09:57 PM

View Posttoxicwolf, on 12 October 2012 - 03:10 PM, said:

Just to let you know, this doesn't work properly with the new CC v1.45 beta. It is missing the colour related functions.
Yeah I'll update it when I have a chance. Not a priority to me now, so might take some time. Also, 1.45 is just a beta, so maybe it's better to wait for the release (in case something changes).

#16 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 13 October 2012 - 12:48 PM

View PostMysticT, on 12 October 2012 - 09:57 PM, said:

View Posttoxicwolf, on 12 October 2012 - 03:10 PM, said:

Just to let you know, this doesn't work properly with the new CC v1.45 beta. It is missing the colour related functions.
Yeah I'll update it when I have a chance. Not a priority to me now, so might take some time. Also, 1.45 is just a beta, so maybe it's better to wait for the release (in case something changes).
No worries, was just giving you the heads up. I've already done a kind of un-official update of my local copy and it works fine. But waiting for the full 1.45 release before officially updating Sync API is a good idea.

#17 fattigfaan

  • New Members
  • 3 posts

Posted 17 October 2012 - 10:18 AM

Is there a way i can set the monitor size?
I have mine at like 8*5 atm, but I'm not sure how to get it to stretch.
It works fine if i run it on the monitor outside the API though.

#18 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 17 October 2012 - 04:39 PM

View Postfattigfaan, on 17 October 2012 - 10:18 AM, said:

Is there a way i can set the monitor size?
I have mine at like 8*5 atm, but I'm not sure how to get it to stretch.
It works fine if i run it on the monitor outside the API though.
By default it uses the smallest size of all the targets (console and monitors), but you can change that behaviour with useMaxSize (I forgot to include it in the usage :D/>, added now).
Example:
sync.addMonitor("left") -- add the monitor on the left
sync.useMaxSize(true) -- use maximum size, so all the monitor is used
sync.redirect(true) -- add the terminal and redirect.
print("This is on the monitor and the console. It should use the whole monitor width for this text...")
sync.useMaxSize(false) -- use minimum size
print("This is also on the monitor and the console, but it should use the console size now...")


#19 fattigfaan

  • New Members
  • 3 posts

Posted 17 October 2012 - 06:03 PM

When using that, the console text moves outside, but i can see it come up on the monitors behind. So it's not limited by the console =s

#20 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 17 October 2012 - 07:33 PM

View Postfattigfaan, on 17 October 2012 - 06:03 PM, said:

When using that, the console text moves outside, but i can see it come up on the monitors behind. So it's not limited by the console =s
Well, it can only use one size. So, it's either the console or the monitor...
It would be too hard to use multiple sizes, and it would probably break the default print/write functions, so I don't think I'll change it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users