[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Newbie: Cooperative Multitasking
- From: Jeroen Janssen <japj@...>
- Date: Thu, 04 Nov 1999 08:28:39 +0100
Derek Wong wrote:
> Hi everybody,
> I'm new to the list and new to lua. I was wondering if someone might
> offer me some advice at implementing cooperative multitasking with
> lua scripts. I'm an amateur programmer so please excuse me if I've
> used the wrong terminology.
Well (it's some time ago that I've been using lua, but) here are some ideas regarding cooperative multitasking (these
ideas are relative simple to implement I did it some time ago as an experiment when I was trying to find a way to get
lua working with my demosystem where there's a list of (graphical) tasks that should be executed cooperatively...
anyway.. I remember Bret to implement multitasking by rewriting some things in lua (don't know if it's *that* simple
anyway, but that's something Bret might care to comment about) resulting in lua having some cooperative multitasking
You could creete a C++ base 'task' class with a virtual 'run' function. export this class to lua (with tolua). create a
new lua class derived from 'task', create a new C++ class derived from 'task' and export this class to lua.
Next create a lua function addtask that can add a specified task to a lua list. Last create a runtasks function in lua
that can iterate through the list and call appropriate run functions
because you exported the C++ class to lua and because you iterate the list from within lua this will allow both the C++
run functions as well ass the lua run functions to be executed in a cooperative multitasking way. Just make sure that
whatever you want to do from C++ is added to the list.
This idea can be 'enhanced' by adding a flag variable to the base class that has information about wether or not to
execute the run function (thus allowing some form of 'pause' functionality).
I hope this makes some sence, if not ..... then please let me know :) it's been some time that I've been working with
lua, but I think that the mailinglist might contain some more information about what I've been trying do explain here.
The consensus seemed to be that if really large numbers of men were sent to
storm the mountain, then enough might survive the rocks to take the
citadel. This is essentially the basis of all military thinking.
-- (Terry Pratchett, Eric)