What's the advantage of Stackless Python's microthread than Lua's coroutine in state machine implementation for game?
Are there any advantages to Stackless Python implementation over Lua's coroutines?
What's the difference between them?
Solution
Stackless Python and tasklets
(I haven't done any programming with Stackless Python, but I have read some of the details about how it is implemented):
Pros:
Lightweight most of the time.
Has scheduler to manage which tasklet get resume next after the current one yields.
Support for Preemptive Scheduling. (i.e. run for X instructions)
Channels for communication between tasklets.
Cons:
Sometimes need C-stack when yielding from a tasklet. (i.e. when yielding from some C callbacks)
Lua 5.1 with plain coroutines:
Pros:
Lightweight.
resume()/yield() functions allow consumer/producer model of communication.
Cons:
No built-in scheduler. You have to manage resuming & yielding coroutines.
Can't yield from a C function, a metamethod, or an iterator. (Lua 5.2 will remove most of these restrictions, LuaJIT 1.1 provides lightweight c-stack switching to yield from anywhere)
No built-in Preemptive Scheduling support. (would have to use debug hooks)