Jump to content




Gopher's APIs - Old, and broken, but still good. Yah. Still good.

api

83 replies to this topic

#21 GopherAtl

  • Members
  • 888 posts

Posted 12 January 2013 - 07:49 PM

I will probably rework the example to not be an example startup file, or at least include an example use without the startup file, as in most cases it is probably better to call run() in your program rather than having goroutines running behind the shell. I have some changes planned which will make it behave better when run globally from startup, but making the changes hasn't been a priority.

Unrelated, I belatedly updated the main post to document some new features I posted to the pastebin version a couple of weeks ago. Spawned coroutines can now have their own specified terminal redirect objects, which will automatically be used whenever the routine runs.

#22 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 12 January 2013 - 07:58 PM

View PostGopherAtl, on 12 January 2013 - 07:49 PM, said:

I will probably rework the example to not be an example startup file, or at least include an example use without the startup file, as in most cases it is probably better to call run() in your program rather than having goroutines running behind the shell. I have some changes planned which will make it behave better when run globally from startup, but making the changes hasn't been a priority.

Unrelated, I belatedly updated the main post to document some new features I posted to the pastebin version a couple of weeks ago. Spawned coroutines can now have their own specified terminal redirect objects, which will automatically be used whenever the routine runs.
I've figured everything out(I believe) and it's just amazing. Absolutely incredible! By the way, I'm planning on making an OS, and this API would be a huge part of it. My question to you is, could I put this API into my code so people wouldn't have to download a bunch of things? You'd surely get credit in the credits.

#23 GopherAtl

  • Members
  • 888 posts

Posted 12 January 2013 - 08:33 PM

Sure, so long as I'm credited in some way, do with it as you will. :)

#24 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 12 January 2013 - 08:34 PM

View PostGopherAtl, on 12 January 2013 - 08:33 PM, said:

Sure, so long as I'm credited in some way, do with it as you will. :)
Thanks so much! :D

#25 ArchAngel075

  • Members
  • 149 posts

Posted 13 January 2013 - 01:15 AM

View PostGopherAtl, on 12 January 2013 - 05:34 AM, said:

Took me a minute to figure out what you meant, as the API doesn't use rednet; you meant in the sample program! I was deliberately keeping the sample program simple, as the point is to demonstrate basic use of goroutines, but for real rednet programs, this is a good suggestion!

yeah, i looked at it now and read the fine print stating "sample program" my mistake :)

#26 Exerro

  • Members
  • 801 posts

Posted 13 January 2013 - 07:38 AM

ok this looks very interesting but i dont have a clue if it will do what i need...i need a program to run the shell and modify the term and os api so my program gets every key pressed and every char written to the screen but if i use parallel either it will only display once or keep running the shell over and over again...i want something that will run a coroutine in the background even after the program has finished...can this api do that?
edit: I downloaded it and every time i try running it a random number is displayed :l the number is 24

edit2: got something working but now i implemented my code it doesnt work
Spoiler


#27 GopherAtl

  • Members
  • 888 posts

Posted 13 January 2013 - 10:09 AM

It looks like what you want is a redirect wrapper that buffers what is written to the screen. I have an api for that as well that I was planning to release eventually. I'm not sure what you want to do with the buffer exactly, but the two together may let you do it with ease.

The buffer is on pastebin here: http://pastebin.com/fU9Kj9zr ( pastebin get fU9Kj9zr buffer )

here's a simple example I threw together, uses goroutines and buffers to run a shell with a background coroutine that prints the contents of the screen to a file when you press F12. (only prints the characters, not the color data - you can access color info just as easily though) Lots of detailed comments in this, plus as a bonus included my usual error logging coroutine, which is a must-have when debugging programs using goroutines.

Spoiler

you can grab this program from pastebin as well, here http://pastebin.com/khYEAUDM ( pastebin get khYEAUDM example ) If you're not calling os.loadAPI on buffer and goroutines in startup, or just using this as startup, you'd have to add the lines to the top to load both APIs first.

#28 Exerro

  • Members
  • 801 posts

Posted 14 January 2013 - 01:24 AM

i was trying to make a recording program and term.write would go through the program first and save it

#29 GopherAtl

  • Members
  • 888 posts

Posted 14 January 2013 - 09:25 PM

you would probably want to implement a custom redirect buffer to do that. The code for the buffer api might give you some ideas how to approach that; basically you'd want to append to a file each call to write, clear, clearLine, setCursorPos, and maybe setCursorBlink, probably with timing data, in a way that could be read and repeated by another program.

two basic approaches: it could run from shell, similar to the mon command to run a program on a monitor, where you say, ex, "record worms" and it runs worms, recording it. Wouldn't need goroutines for that. Other option is having goroutines run in startup, putting a video capture routine in the background, with recording toggled by pressing some key. That would use coroutines, tho not necessarily goroutine (parallel.waitForAny in startup could do the same).

Explaining in more detail than that is beyond the scope of this thread, I'm afraid!

#30 GopherAtl

  • Members
  • 888 posts

Posted 16 January 2013 - 05:14 PM

Bump for complete rework of the original thread, and the formal introduction of the redirect api (previously the buffer api).

Also integrating ctrlkeys here, requested the original thread be locked. One thread will be easier to follow/manage, and my apis are increasingly designed to be used together.

#31 Eric

  • Members
  • 92 posts
  • LocationUK

Posted 17 January 2013 - 12:33 PM

Where'd the download link for goroutines go? I'd like to read the code, but there seems to be no download link!

#32 GopherAtl

  • Members
  • 888 posts

Posted 17 January 2013 - 12:34 PM

oh! sorry about that, somehow overlooked that when compeltely redoing the post >.< fixing now...

#33 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 19 January 2013 - 03:28 PM

Used goroutine.launch() in startup without anything else, (testing for what it does :P) and it crashed my MC when i went into the world... every time o_O XD

#34 GopherAtl

  • Members
  • 888 posts

Posted 19 January 2013 - 05:12 PM

crashed the cc computer, or minecraft? O_o and version?

#35 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 20 January 2013 - 05:03 AM

crashes my minecraft window, and goroutine current version and cc 1.481

#36 GopherAtl

  • Members
  • 888 posts

Posted 20 January 2013 - 05:40 AM

show me your startup file?

I'm assuming you weren't checking if it was loaded already, though I'm rather surprised that would crash minecraft - just tried it myself, didn't do anything like that for me. Anywy, give the update a try.

#37 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 20 January 2013 - 01:14 PM

Here's my startup:

os.loadAPI("goroutine")
goroutine.launch()

Edit: Trying da update...

Edit: Edit: Replicated error on a new world with that script( latest version ), and then opening a new computer. The CC computer screen went blank, and then MC crashed.

Edited by MudkipTheEpic, 20 January 2013 - 01:33 PM.


#38 GopherAtl

  • Members
  • 888 posts

Posted 20 January 2013 - 05:37 PM

wait, you're installing it into rom?

...

don't do that. It is designed to run from the normal startup, after everything else has loaded. I might look into making a version meant to be installed in rom, but it would install itself very differently than this does.

:edit: I've added the check directly to the launch function which may eliminate the problem for you, but it was not intended to be run that way so. You say you placed an ew computer and opened it and it immediately crashed, so where exactly are you putting that?

#39 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 21 January 2013 - 04:10 AM

View PostGopherAtl, on 20 January 2013 - 05:37 PM, said:

wait, you're installing it into rom?

...

don't do that. It is designed to run from the normal startup, after everything else has loaded. I might look into making a version meant to be installed in rom, but it would install itself very differently than this does.

:edit: I've added the check directly to the launch function which may eliminate the problem for you, but it was not intended to be run that way so. You say you placed an ew computer and opened it and it immediately crashed, so where exactly are you putting that?

Actually, I installed it into a regular computer's startup, not rom/startup. Here's what I did:
  • Place cpu down.
  • Get goroutine off pastebin.
  • Write that script in "edit startup".
  • Reboot cpu. Cpu will start to flash the CraftOS screen.
  • Place another cpu down.
  • Screen will be blank, and Minecraft will crash in a few seconds.

Trying the new version now.....

Edit: You dont even have to place another CPU down! Mc crashes with no error screen. The console said it spawned 1964 coroutines..... o_O

Edited by MudkipTheEpic, 21 January 2013 - 04:15 AM.


#40 GopherAtl

  • Members
  • 888 posts

Posted 21 January 2013 - 05:09 AM

View PostGopherAtl, on 20 January 2013 - 05:40 AM, said:

show me your startup file?

I'm assuming you weren't checking if it was loaded already, though I'm rather surprised that would crash minecraft - just tried it myself, didn't do anything like that for me. Anywy, give the update a try.

Check if it is loaded before loading. the startup code in the OP gives you code to do this.



View PostGopherAtl, on 17 October 2012 - 01:41 AM, said:

goroutine

Usage
Spoiler

Still no clue why this crashes for you, tho, doesn't cause any problems at all for me even when I deliberately run it wrong, as you seem determined to do.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users