Meaning of the `from` parameter of `lua_resume`

拟墨画扇 提交于 2019-12-10 16:01:56

问题


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 resuming L. If there is no such coroutine, this parameter can be NULL.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!