[Stackless] lua vs. stackless python

Jeff Senn senn at maya.com
Fri Apr 24 16:30:06 CEST 2009

On Apr 23, 2009, at 4:36 PM, Richard Tew wrote:
> Whether someone would choose Lua or Stackless Python for coroutines is
> probably a matter of preference for the language itself.  But one
> thing Stackless might provide that Lua does not, is the ability to
> block C function calls as well as Python function calls given that we
> shift C stack sections in and out with tasklets.  Or the ability to
> persist and unpersist in a cross platform way, running tasklets.

To clarify a couple of points:

> Stackless, going from my limited understanding here, is not  
> 'actually stackless' at all -- but by manipulating the C stack,  
> allows dynamic switching between (arbitrary?) frames.  I have read  
> that lua is 'literally stackless', and does not use a C stack at  
> all... correct?  Please, scientists and engineers, tell me what this  
> means to me...

Stackless does use the C-stack, but sparingly, and except for when C  
extensions call back into python,
it is "unrolled" between task switching.  So essentially it is "C  
stackless" in (dare I say) *most* cases.
When there *are* extension callbacks -- then the C-stack needs to be  
copied and dynamically patched.

So it's sort of the best of both worlds.

> Stackless's 'tasklets' weigh only a few kilobytes a piece; what does  
> a lua coroutine weigh?

When there are extension callbacks the stackless tasklets *could* be  
much more weighty...
depending one what is on the stack.

More information about the Stackless mailing list