lua-users home
lua-l archive

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




2015-05-14 3:16 GMT+08:00 William Ahern <william@25thandclement.com>:

ES6 generators are a far cry from Lua's coroutines:

1) ES6 generators require a special function definition.
2) Lua's coroutines are symmetric--yield can return values provided by 
resume.

3) ES6 yield can only be used in the generator function, whereas you can
yield from any function in the Lua coroutine call stack.

Yes, you are right. Even the proposed ES7 async/await should add async keyword
to the function definition.

Furthermore, Lua's coroutine implementation is unique in real-world
languages in that it's stackless--it doesn't rely on the C stack to
implement coroutines, even when using the C API. (Stackless Python is only
stackless for Python code.) That has useful performance, memory, and
debugging characteristics. On some older platforms (notably the old
LinuxThreads implementation) you can't mix POSIX threads with fibers (the
Windows term for application-created C stacks), and in the future this
limitation may return in the form of security measures on more popular
platforms.

Lua's coroutine is great for its true stackless. Every normal function can be used
in coroutine thread. But stackless means a full separate Lua stack should be maintained
for each coroutine, which may cause more garbage memory refered from the earlier
frames of these stacks will be kept. Considering the not-so-great GC in Lua, this
may not be a good thing in some conditions.

Regards,
Zenk Ju