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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With