diff options
| author | ame <[email protected]> | 2025-11-24 21:19:57 -0600 |
|---|---|---|
| committer | ame <[email protected]> | 2025-11-24 21:19:57 -0600 |
| commit | 691a82c3a7ce7e5f43a15f8751cacc792efa339f (patch) | |
| tree | 14945a44c9c96ccbecbb8f84946176d2e2703590 | |
| parent | 07eeacf5b013061d6e76505ad08c5c9581fecfba (diff) | |
better error and better thread:res return
| -rw-r--r-- | src/lua.c | 3 | ||||
| -rw-r--r-- | src/thread.c | 15 |
2 files changed, 10 insertions, 8 deletions
@@ -272,10 +272,11 @@ void luaI_deepcopy(lua_State* src, lua_State* dest, enum deep_copy_flags flags){ lua_pushlightuserdata(dest, lua_touserdata(src, -1));
break;
case LUA_TTHREAD:
+ sprintf(stderr, "unable to copy LUA_TTHREAD, pushing nil\n");
lua_pushnil(dest);
break;
default:
- printf("unknown type %i vs (old)%i\n",lua_type(src, -1), type);
+ sprintf(stderr, "unknown type %i vs (old)%i\n",lua_type(src, -1), type);
//abort();
lua_pushnil(dest);
break;
diff --git a/src/thread.c b/src/thread.c index ee84a65..fbf5f01 100644 --- a/src/thread.c +++ b/src/thread.c @@ -104,11 +104,8 @@ int l_res(lua_State* L){ lua_pushvalue(L, idx);
lua_setglobal(L, "_return_table");
- info->done = 1;
- pthread_mutex_unlock(&*info->lock);
-
- pthread_exit(NULL);
- p_error("thread did not exit");
+ lua_pushstring(L, "res():exit");
+ lua_error(L);
return 1;
}
@@ -180,7 +177,12 @@ void* handle_thread(void* _args){ lua_assign_upvalues(L, x);
lua_pushvalue(L, res_idx);
- lua_call(L, 1, 0);
+ if(lua_pcall(L, 1, 0, 0) != LUA_OK){
+ if(!(lua_type(L, -1) == LUA_TSTRING && strcmp("res():exit", lua_tostring(L, -1)) == 0)){
+ lua_error(L);
+ }
+ lua_pop(L, 1);
+ }
args->done = 1;
pthread_mutex_unlock(&*args->lock);
@@ -206,7 +208,6 @@ int _thread_await(lua_State* L){ env_table(L, 0);
luaI_jointable(L);
-
lua_setglobal(L, "_locals");
lua_getglobal(info->L, "_return_table");
|
