lua_resume的from参数的含义 [英] Meaning of the `from` parameter of `lua_resume`

查看:413
本文介绍了lua_resume的from参数的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 Lua 5.2参考手册:

int lua_resume (lua_State *L, lua_State *from, int nargs);

[...]

参数from代表要恢复L的协程.如果没有这样的协程,则此参数可以为NULL.

The parameter from represents the coroutine that is resuming L. If there is no such coroutine, this parameter can be NULL.

但这对我来说并不多.它到底是做什么的?在什么情况下,我必须传递除NULL以外的任何内容?

But it does not say much to me. What exactly does it do? In what circumstances I must pass anything other than NULL?

推荐答案

源代码(对于5.2)看来,from仅用于正确计算简历中嵌套C调用的数量.

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;

lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));

coroutine.resume 的实现似乎正在使用它这样.

The implementation of coroutine.resume seems to use it that way.

它使用恢复它的主线程的from值在协程线程上恢复协程.

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);

这篇关于lua_resume的from参数的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆