Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of the `from` parameter of `lua_resume`

Tags:

c

lua

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?

like image 303
Yakov Galka Avatar asked Sep 30 '22 15:09

Yakov Galka


1 Answers

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);
like image 88
Etan Reisner Avatar answered Oct 03 '22 00:10

Etan Reisner