Jump to content




Coroutine and event manager


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

#1 Kepler

  • Members
  • 65 posts

Posted 04 August 2017 - 07:34 AM

A combined coroutine manager and event callback handler.

An alternative to placing all logic in a single os.pullEvent while loop.
Event handlers are run in separate coroutines and are not reentrant.
Easily add new coroutines at any time (before or after event loop has started).
Advanced control of coroutines using the returned handler object.

Installation
pastebin get Yek469px event.lua

Code
Spoiler

Simple Example
Spoiler

Documentation
Spoiler

Edited by Kepler, 07 August 2017 - 07:49 PM.


#2 Dave-ee Jones

  • Members
  • 456 posts
  • LocationVan Diemen's Land

Posted 07 August 2017 - 03:42 AM

Interesting idea, though in some of those functions (particularly your 'char' function) I don't like the way you do some things. E.g. Testing for key 'Enter' pressed by calling the read() function. That's just lazy :P
AddRoutine's sleep(1.5) isn't ideal either. It's quite crude.

If you want it to look and act more accurately you should use timer events and key press events. Otherwise, good job.

#3 Kepler

  • Members
  • 65 posts

Posted 07 August 2017 - 07:06 PM

View PostDave-ee Jones, on 07 August 2017 - 03:42 AM, said:

Interesting idea, ...

Hmm, maybe I did not write this post clearly. What you are looking at is an example of using the API. The example code is very simple to just show how to use the API. Take a look at the linked pastebin code. I'll update this post when I get a chance.

Thanks for the feedback.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users