From 72143a494b25c2df614c3952a81563d5eebdb5b7 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 13 Sep 2017 11:45:31 -0400 Subject: [PATCH] don't forget to pop! --- single/sol/sol.hpp | 9 +++++---- sol/reference.hpp | 5 +++-- tests/test_storage.cpp | 6 ++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index d48770c8..e25b3dee 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2017-09-13 15:37:13.293030 UTC -// This header was generated with sol v2.18.3 (revision 7ff3a39) +// Generated 2017-09-13 15:45:14.036087 UTC +// This header was generated with sol v2.18.3 (revision a068c4e) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -5916,8 +5916,9 @@ namespace sol { if (L == nullptr) return backup_if_unsupported; lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); - L = lua_tothread(L, -1); - return L; + lua_State* Lmain = lua_tothread(L, -1); + lua_pop(L, 1); + return Lmain; #endif // Lua 5.2+ has the main thread getter } diff --git a/sol/reference.hpp b/sol/reference.hpp index afd1d2f0..7b85d24a 100644 --- a/sol/reference.hpp +++ b/sol/reference.hpp @@ -141,8 +141,9 @@ namespace sol { if (L == nullptr) return backup_if_unsupported; lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); - L = lua_tothread(L, -1); - return L; + lua_State* Lmain = lua_tothread(L, -1); + lua_pop(L, 1); + return Lmain; #endif // Lua 5.2+ has the main thread getter } diff --git a/tests/test_storage.cpp b/tests/test_storage.cpp index 00773a35..f03e6c78 100644 --- a/tests/test_storage.cpp +++ b/tests/test_storage.cpp @@ -31,4 +31,10 @@ TEST_CASE("storage/main thread", "ensure round-tripping and pulling out thread d lua_State* ts = sol::main_thread(lua, lua); REQUIRE(ts == orig); } + { + sol::stack_guard g(lua); + lua_State* orig = lua; + lua_State* ts = sol::main_thread(lua); + REQUIRE(ts == orig); + } }