Jump to content




Coroutines, Buffers, Gophers API, and help?

api lua help

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

#1 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 23 March 2015 - 04:08 PM

So I have an idea to implement a multitasking based off multishell, now the idea I had was being able to disable the top tab bar and just make my own version of the tab menu, but...

How would I start? Would this count as a coroutine manager and buffer?

So when I change tab it will always store what was on the other tab and when I come back it is still there?

Edited by DannySMc, 24 March 2015 - 05:25 PM.


#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 23 March 2015 - 04:48 PM

the default multi-shell makes a lot of use of the default window api, you will need to look at both for a good understanding

also, a lot of people have made their own, it may help to look at their code too

#3 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 23 March 2015 - 04:52 PM

Every 'tab' would have it's own buffer to write graphics to. Every new program would probably be ran in a coroutine. So yes, you'll need a coroutine manager and a buffer system. There's a great tutorial on CC-specific coroutine management here.

#4 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 23 March 2015 - 06:46 PM

Yeah but the multishell has all of that already.. From looking at the code... I was just wondering if anyone could help me. This is the second post I have made about this, I get how coroutines work I just want to know how to apply them into an actual program, like when I create a coroutine, how would I index it? So if someone downloaded an app, how do I run that as a coroutine and index it? Example:
local co1 = couroutine.create(function ()
	print("Hello World!")
end)

Do I index it like:
tProcesses = {}
table.insert(tProcesses, co1)

Then run it like:
tProcesses[1]
--or
tProcesses.co1()
[/SPOILER]

The example means that I want to make it dynamic not just make a few coroutines for set functions, I want to be able to make many functions like:
[CODE]
thread.new(nameofprocess)
or something like that.

This is where I don't understand, 'tis why I said about multishell because everything is there, it uses the Window API as a buffer and redirects to different coroutines, like I don't understand how you can yield one coroutine then run another and keep some kind of taskbar still there, which is why I asked about multishell.

I don't learn from reading I learn by taking apart someone else's code or someone writing up so code and walking me through it, I get simple coroutines, but not the multitasking (like other people's OS's can do)?

Edited by DannySMc, 23 March 2015 - 06:47 PM.


#5 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 23 March 2015 - 07:09 PM

That tutorial I linked actually explains how multitasking works in CC. After you read that, I would suggest to first examine the parallel API code, it's a bit shorter and simpler than Multishell. Once you get that, move on to Multishell.

After looking at your example with putting something into a table, do you know exactly how tables and the table library works?

local myTable = {"first"}

table.insert(myTable, "second")
-- same as:
myTable[#myTable + 1] = "second"

myTable #--> {"first", "second"}

table.insert(myTable, 2, "third")
-- same as:
myTable[3] = myTable[2]
myTable[2] = "third"

myTable #--> {"first", "third", "second"}

Edited by MKlegoman357, 23 March 2015 - 07:10 PM.


#6 KingofGamesYami

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

Posted 23 March 2015 - 10:14 PM

To run a coroutine, use coroutine.resume( co, args ) where args are event information. If event information is omitted, nothing will work.

#7 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 23 March 2015 - 10:17 PM

View PostMKlegoman357, on 23 March 2015 - 07:09 PM, said:

That tutorial I linked actually explains how multitasking works in CC. After you read that, I would suggest to first examine the parallel API code, it's a bit shorter and simpler than Multishell. Once you get that, move on to Multishell.

After looking at your example with putting something into a table, do you know exactly how tables and the table library works?

local myTable = {"first"}

table.insert(myTable, "second")
-- same as:
myTable[#myTable + 1] = "second"

myTable #--> {"first", "second"}

table.insert(myTable, 2, "third")
-- same as:
myTable[3] = myTable[2]
myTable[2] = "third"

myTable #--> {"first", "third", "second"}

Yeah I do, very familiar with it, I just don't know how coroutines work as some kind of menu system, if someone could explain in detail the steps I have said before that would be very useful, thanks.

#8 Bomb Bloke

    Hobbyist Coder

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

Posted 23 March 2015 - 11:50 PM

Danny, no offense, but after your last thread I have difficulty believing you've even fully read bubba's tutorial. Trying to get you to pinpoint the bits you're having trouble with was like pulling hen's teeth - I couldn't get you to do it.

If it helps, think of a coroutine as a function which returns every single time it yields, but until it returns "properly", it can be resumed from where it left off. Every time it yields, it's able to return data - think of coroutine.yield("char") (or os.pullEvent("char"), they boil down to nearly the same thing) as being sorta like return "char" - and every time it resumes, it expects data back - think of coroutine.resume(myFunc, "char", "p") as being sorta like myFunc("char", "p").

You don't have to pass event filter requests or event data back and forth when yielding or resuming, but that's the convention with ComputerCraft, and nigh-all user scripts will expect you to do it that way.

Again, if you can't wrap your head around the parallel API's code - a very simple coroutine manager - then you're not ready to look into running menu systems alongside coroutines, either.

#9 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 09:41 AM

No I seriously did read it, I understand it I just am not completely sure how to make like a manager? If you get what I mean? I shall have a look at the parallel API.

#10 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 11:55 AM

Hey there,
I have been advancing a little bit and found an API that I like the look of, the only thing I am not sure about is the following:

I get how to initialize the parent couroutine. I know how to spawn more in, but how do you like say switch back to another coroutine? do you just use a break in the coroutine? so a while true do and then break it and it will return to the parent?

As I made a code which would spawn a new coroutine, but it goes to that coroutine? How could I spawn them in the background, and run them when I want, so If I have OEEDS browser and say sketch, how would I run both of them and then switch between them, now I know how to make an interface etc for it, I just need to know how to actually go to it, because you have thread.run() and thread.spawn() but there is no like, thread.resume() etc...?

NOTE: I named the api "thread".

Pastebin link to Gopher's API

EDIT ON THIS:

How do you run a seperate program from this? so instead of using functions how would you specify a program? and load that into a function? and run it as a coroutine?

Edited by DannySMc, 24 March 2015 - 12:03 PM.


#11 KingofGamesYami

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

Posted 24 March 2015 - 12:32 PM

local program_function = loadfile( "program" )
--#now it's a function; you can use it


#12 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 12:38 PM

View PostKingofGamesYami, on 24 March 2015 - 12:32 PM, said:

local program_function = loadfile( "program" )
--#now it's a function; you can use it
Ahh that's awesome thank you! Any idea on the other parts?

#13 KingofGamesYami

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

Posted 24 March 2015 - 12:46 PM

Perhaps you could use the spawnBackground function on line 222?

Edit: Oh, also it'll return to the parent any time it yields, ei pulls an event. (I think, it's not my API)

Edited by KingofGamesYami, 24 March 2015 - 12:47 PM.


#14 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 12:48 PM

View PostKingofGamesYami, on 24 March 2015 - 12:46 PM, said:

Perhaps you could use the spawnBackground function on line 222?

Edit: Oh, also it'll return to the parent any time it yields, ei pulls an event. (I think, it's not my API)

Okay thank you :)

#15 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 02:39 PM

Does anyone have some kind of coroutine and buffer setup? As I just want a simple API that will allow me to switch between co routines and the buffer will be redrawn? As Gopher's API doesn't have a buffer. I don't know how to make one either...

#16 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 03:35 PM

Hello,

I have been looking around for some kind of buffer and coroutine manager but to no avail have I found one... Is anyone know of one that allows me to use simple functions to get the desired outcome as Gopher's API doesn't have a buffer and multishell, simply doesn't want to work for me...?

Thanks

EDIT:
I just need something like what Nova Horizon has, I want to be able to get a table of running coroutines as well as be able to create, run, kill, run in background etc?

Edited by DannySMc, 24 March 2015 - 04:26 PM.


#17 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 04:20 PM

Anyone?

#18 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 24 March 2015 - 04:26 PM

Do you really expect anyone to reply in one hour? Wait a day, well, at least 12 hours. I think that you should have just posted all these recent questions about coroutines in one thread, because you're addressing basically the same problem in each of the thread. I'm not aware of any coroutine manager and buffer which works together as an API on the forums.

Edited by MKlegoman357, 24 March 2015 - 04:26 PM.


#19 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 24 March 2015 - 04:29 PM

View PostMKlegoman357, on 24 March 2015 - 04:26 PM, said:

Do you really expect anyone to reply in one hour? Wait a day, well, at least 12 hours. I think that you should have just posted all these recent questions about coroutines in one thread, because you're addressing basically the same problem in each of the thread. I'm not aware of any coroutine manager and buffer which works together as an API on the forums.

Well I understand that but I am getting frustrated with not knowing how this works, I am just becoming impatient which is my fault, just want something that will work because I am so confused with all of this :/

#20 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 March 2015 - 04:45 PM

Threads merged.

We'd like to help you, but you keep jumping around. Let's start with the coroutine tutorial Bubba wrote, linked earlier in the thread. What, specifically, did you not understand in it? Feel free to ask a lot of questions in this thread, but do please try to make them as specific as you can. Maybe start from the beginning of the tutorial and post questions here about things you aren't grasping until we've gotten you through the whole tutorial. We can't help you unless we know specifically what parts of the system you don't understand.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users