lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jun 19, 2002 at 03:30 -0400, Sean Middleditch wrote:
> 
> No one said get rid of co-routines - saying get something in addition to
> co-routines, i.e. a fast an optimized schedular in the Lua core (versus
> tricks and hacks in Lua byte-code), and maybe even a pre-emptive or
> soft-pre-emptive system for thread switching.

I think this is a good candidate for an experimental patch.  You could
do a scheduler like this with the simple addition of a instruction
countdown timer in the VM which yields when the timer hits 0.  Or,
look into the signal handler ideas that were mentioned earlier.
Everything else about the scheduler could be implemented externally to
Lua, using existing coroutine API.

> People argue that making game scripters worry about race conditions and
> such is bad - I make the same argument that trying to teach them to
> break scripts up into small pieces is bad.  A compromise is needed.

I totally agree with both arguments.  Easy compromise: put some
yield's in the scripts.  You should be able to hide them in "blocking"
library routines.  E.g. you provide a "go_to_point(x)" routine, which
keeps yielding until the entity gets to the requested point.  The
high-level scripter doesn't need to necessarily worry about yield()
directly.

>  One can be coded that allows either system to exist, even
> simultaneously (with some cleverness). This has been discussed over
> and over, and doesn't seem like it's going happen - Lua is just not
> going to be _the_ game scripting language, it seems, and that's
> that.

If you want a scheduler, I encourage you to make an experimental patch
and put it in the PowerPatches section on the wiki.  The Lua authors
pay attention to how people react to those patches.  That's partly how
yield() ended up in 5.0work0 -- I wanted the functionality, argued for
it, got nowhere, and made a (buggy) patch, which got a good response.
The Lua authors took note of this and did a better implementation for
5.0work0.

-- 
Thatcher Ulrich
http://tulrich.com