Threading and Coroutines.
Exercises, examples and other material relating to training module U114. This topic is presented on public courses Learning to program in Lua
, Lua Programming
, Lua Programming
|Articles and tips on this subject||updated|
|4270||Embedding Lua to perform tailored code at an interval|
Lua is a language that's commonly embedded within other products - a game, or a control system, for example - in order to provide a programmable tailoring of that other product. It's a great language for that - it's small, it's free, it has a suitable open source license, and it comes as a C library ...
|3395||Parallel but not really parallel. Moving game characters. Coroutines in Lua. |
Virtual World game programming involves moving many characters - both player controlled and automatic - in parallel. The movements of each character depend - to a greater or lesser extent - on the prior movements of the character, and of the other charcaters and the resultant position and condition that ...
|2455||Lua examples - coroutines, error handling, objects, etc|
I have presented a bespoke Lua course over the last three days ... and it has lead me to some interesting new examples which I'm sharing here.
Object Orientation is more a way of thinking and coding than a language feature in Lua - when you set up a piece of data / structure / object, you do so in a ...
|2314||Passing parameters to a coroutine in Lua|
Lua's coroutines, like Python's generators, provide for something which is akin to lightweight threading - rather than a strict functional calling stack, where one function must be completed before another is invoked, you can call a code block (function or method) and have it yield back to the calling ...
|1870||What to do with a huge crop of apples|
Last year, you had a good crop of apples on your tree .... what did you do with them? Make apple pies for all the neighbours! How?
• You collect all the apples and bring them into the kitchen.
• You prepare the apples ready for the pies.
• You make the pastry and apple pies.
• You ...
|1699||If you are learning Lua, here are some more examples|
During some courses, I write few (if any) new examples in front of my delegates, rather relying on the standard ones in the training notes (which I wrote anyway!) and making small changes and adjustments to illustrate how things work. On other courses, though, I write a some new examples from scratch ...
|1691||Co-routines in Lua - co-operative processing|
CoRoutines in Lua allow you to have a number of pieces of co-operative code which (whilst theyâ€™re not running in parallel in a true multithreaded way) allow you to progress through multiple strands of your code at the sametime.
Letâ€™s take an example. I have a rather large text file that ...
Examples from our training material
|charmoves|| coroutine for game player movements|
|controller|| setting off a number of timers|
|coro|| simple coroutine example|
|cosy|| Illustration of Coroutines |
|crcr|| coroutine basics|
|datafeeder|| using a coroutine as a generator|
|ff2.lua|| Multiple coroutines in parallel use|
|inco|| Passing parameters to coroutines|
|nocoro|| NOT using coroutines - filling a table then using it instead|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
Coroutines as co-operative programs.
Transferring control and maintaining state.
Concurrent tasks, and keeping them apart.
Event handling - event loops and yielding
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.