Better error message on failed coroutines

Add a full error message with traceback if the coroutine_iter_next()
function is passed a dead coroutine.
This commit is contained in:
Robin Malley 2022-06-26 23:05:24 +00:00
parent a0c8907f71
commit e0fabca908
1 changed files with 5 additions and 0 deletions

View File

@ -89,6 +89,11 @@ int coroutine_iter_next(struct co_obj *obj){
lua_rawgeti(L,LUA_REGISTRYINDEX,obj->ref); lua_rawgeti(L,LUA_REGISTRYINDEX,obj->ref);
lua_call(L,1,1); lua_call(L,1,1);
const char *status = luaL_checklstring(L,-1,NULL); const char *status = luaL_checklstring(L,-1,NULL);
if(strcmp(status,"dead") == 0){
kore_log(LOG_ERR,"Coroutine was dead when it was passed to coroutine iter next");
lua_pushstring(L,"Coroutine was dead when passed to coroutine iter next");
lua_error(L);
}
lua_pop(L,lua_gettop(L)); lua_pop(L,lua_gettop(L));
lua_getglobal(L,"coroutine"); lua_getglobal(L,"coroutine");
lua_getfield(L,-1,"resume"); lua_getfield(L,-1,"resume");