Value of the `from`` lua_resume` parameter

From the Lua 5.2 Reference Guide :

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

[...]

The from parameter represents an accompanying copy that resumes L If there is no such coroutine, this parameter may be NULL .

But that doesn’t tell me much. What exactly is he doing? In what circumstances should I pass anything but NULL?

+4
source share
1 answer

Judging by anything other than the source code for 5.2, it would seem that from used only to correctly calculate the number of nested C calls during renewal.

 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 coroutine with text from main thread, which resumes it.

 status = lua_resume(co, L, narg); 
+3
source

All Articles