问题
From Lua 5.2 Reference Manual:
int lua_resume (lua_State *L, lua_State *from, int nargs);
[...]
The parameter
from
represents the coroutine that is resumingL
. If there is no such coroutine, this parameter can beNULL
.
But it does not say much to me. What exactly does it do? In what circumstances I must pass anything other than NULL?
回答1:
Judging by nothing other than the source code for 5.2 it would appear that from
is only used to correctly count the number of nested C calls during the resume.
L->nCcalls = (from) ? from->nCcalls + 1 : 1;
and
lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
The implementation of coroutine.resume seems to use it that way.
It resumes the coroutine on the coroutine thread with a from
value of the main thread that is resuming it.
status = lua_resume(co, L, narg);
来源:https://stackoverflow.com/questions/26347022/meaning-of-the-from-parameter-of-lua-resume