Coroutines: what do we know about them already?

Post Reply
Zah
Posts: 12
Joined: Fri Nov 29, 2013 11:07 pm

Coroutines: what do we know about them already?

Post by Zah »

One of the idea I'm pushing with my Mudmaster chat client is that each socket connection should live in a seperate container that cannot block the main Lua thread.

I see lots of conversation about coroutines before 2012. I know if I call echo() from a coroutine mudlet instantly crashes. What else does the community know about this beyond that? Do all functions that map to TLuaInterpreter crash or just a few?

I don't mind doing this research myself, but why reinvent the wheel if someone else already knows ans is willing to share.

The one thing I've found is that coroutines can touch global variables without crashing. I've throught of doing a message queue to store command messages which a mudlet event polls, pops, and executes.
Code: [show] | [select all] lua
cor = coroutine.create(function ()
	table.insert(mq, function() echo("something") end)
end)
--later on
coroutine.resume(cor)
--later on the polling event pops the function off mq and executes it so echo is ran in mudlet

User avatar
Vadi
Posts: 4826
Joined: Sat Mar 14, 2009 3:13 pm

Re: Coroutines: what do we know about them already?

Post by Vadi »

Yes, all functions from TLuaInterpreter are incompatible with coroutines. Otherwise, coroutines can interact with all variables and use Lua and own-defined functions fine.

Has to do with the way we setup TLuaInterpreter, see https://blueprints.launchpad.net/mudlet ... -for-c-api for an explanation and a proposed solution.

Zah
Posts: 12
Joined: Fri Nov 29, 2013 11:07 pm

Re: Coroutines: what do we know about them already?

Post by Zah »

If I take the time to implement the solution described above is there interest in including it in a release? I imagine it may require a bit more testing than the average PR.

In the intermediate term I will work to see if I can get a message queue approach working.

User avatar
Vadi
Posts: 4826
Joined: Sat Mar 14, 2009 3:13 pm

Re: Coroutines: what do we know about them already?

Post by Vadi »

Yep would be happy to give it a go.

User avatar
Vadi
Posts: 4826
Joined: Sat Mar 14, 2009 3:13 pm

Re: Coroutines: what do we know about them already?

Post by Vadi »

I just use a timer to do the reading.

User avatar
Vadi
Posts: 4826
Joined: Sat Mar 14, 2009 3:13 pm

Re: Coroutines: what do we know about them already?

Post by Vadi »

coroutines are now available in Mudlet 3.2! http://www.mudlet.org/2017/06/mudlet-3-2/

Post Reply