I have some coroutine handling code like this:
int coro_re_num = 0;
int coro_state = lua_resume( coro_lua, master_lua, narg, &coro_re_num);
if ( coro_state == LUA_OK)
{
// do something
}
else if ( coro_state == LUA_YIELD)
{
// do_something
}
else
{
const char* err = lua_tostring(coro_lua, -1);
log_error(err);
}
lua_pop(master_lua, coro_re_num);
When coroutine ends with OK
or YIELD
, it works properly. But when it ends with any error, the last lua_pop
always fail, and I noticed the coro_re_num
is relatively large (mostly more than 10) which causes stack underflow by lua_pop
.
What does the coro_re_num
means when the coroutine ends with error? How to handle it?
lua_pop(master_lua, coro_re_num);