Overhaul of thread handling to support blocking functions other than wait

This commit is contained in:
2022-04-25 17:17:41 -04:00
parent bd389c7815
commit 9aec7c5299
15 changed files with 144 additions and 88 deletions

View File

@@ -76,12 +76,19 @@ int traceback_coroutine(lua_State *L) {
}
int traceback_pcall(lua_State *L, int narg, int nret) {
eng::string traceback_pcall(lua_State *L, int narg, int nret) {
int status;
int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback_coroutine); /* push traceback function */
lua_insert(L, base); /* put it under chunk and args */
status = lua_pcall(L, narg, nret, base);
lua_remove(L, base); /* remove traceback function */
return status;
if (status != LUA_OK) {
const char *msg = lua_tostring(L, -1);
if ((msg == NULL) || (msg[0] == 0)) {
msg = "unknown error";
}
return msg;
}
return "";
}