Fix thread::status() incorrect returning value

This commit is contained in:
FYP 2018-02-11 17:49:42 +03:00 committed by The Phantom Derpstorm
parent 67116a67f9
commit 92f4c4c053

View File

@ -173,11 +173,15 @@ namespace sol {
thread_status status() const { thread_status status() const {
lua_State* lthread = thread_state(); lua_State* lthread = thread_state();
thread_status lstat = static_cast<thread_status>(lua_status(lthread)); auto lstat = static_cast<thread_status>(lua_status(lthread));
int stacksize = lua_gettop(lthread); if (lstat == thread_status::ok) {
if (lstat != thread_status::ok && lstat != thread_status::yielded && stacksize == 0) { lua_Debug ar;
// No thing on the basic_thread's stack means its dead if (lua_getstack(lthread, 0, &ar) > 0)
return thread_status::dead; return thread_status::ok;
else if (lua_gettop(lthread) == 0)
return thread_status::dead;
else
return thread_status::yielded;
} }
return lstat; return lstat;
} }