From 92f4c4c0539797bc66f6dbc166f5a7f10a9ffe27 Mon Sep 17 00:00:00 2001 From: FYP Date: Sun, 11 Feb 2018 17:49:42 +0300 Subject: [PATCH] Fix thread::status() incorrect returning value --- sol/thread.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sol/thread.hpp b/sol/thread.hpp index 3565e006..6472ff51 100644 --- a/sol/thread.hpp +++ b/sol/thread.hpp @@ -173,11 +173,15 @@ namespace sol { thread_status status() const { lua_State* lthread = thread_state(); - thread_status lstat = static_cast(lua_status(lthread)); - int stacksize = lua_gettop(lthread); - if (lstat != thread_status::ok && lstat != thread_status::yielded && stacksize == 0) { - // No thing on the basic_thread's stack means its dead - return thread_status::dead; + auto lstat = static_cast(lua_status(lthread)); + if (lstat == thread_status::ok) { + lua_Debug ar; + if (lua_getstack(lthread, 0, &ar) > 0) + return thread_status::ok; + else if (lua_gettop(lthread) == 0) + return thread_status::dead; + else + return thread_status::yielded; } return lstat; }