`lua_resume`的`from`参数的含义
来自Lua 5.2参考手册 :
int lua_resume (lua_State *L, lua_State *from, int nargs);
[…]
参数
from
表示正在恢复L
的协同程序。 如果没有这样的协程,则此参数可以为NULL
。
但它对我说不多。 它到底是做什么用的? 在什么情况下我必须传递除NULL以外的任何东西?
除了5.2的源代码之外什么都没有看来,似乎from
仅用于在恢复期间正确计算嵌套C调用的数量。
L->nCcalls = (from) ? from->nCcalls + 1 : 1;
和
lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
coroutine.resume
的实现似乎以这种方式使用它。
它使用正在恢复它的主线程的from
值恢复coroutine线程上的协同程序。
status = lua_resume(co, L, narg);