From 305a72a7d27abd4508191c0bfaf24fce4d95d61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Mon, 4 Sep 2017 10:05:23 +0200 Subject: [PATCH] Lua/LuaState: Fix movement not stealing pointer --- include/Nazara/Lua/LuaState.hpp | 4 ++-- include/Nazara/Lua/LuaState.inl | 17 +++++++++++++++++ src/Nazara/Lua/LuaState.cpp | 14 -------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/Nazara/Lua/LuaState.hpp b/include/Nazara/Lua/LuaState.hpp index fe34d794a..cd9e5df86 100644 --- a/include/Nazara/Lua/LuaState.hpp +++ b/include/Nazara/Lua/LuaState.hpp @@ -33,7 +33,7 @@ namespace Nz { public: LuaState(const LuaState&) = default; - LuaState(LuaState&& instance) noexcept; + inline LuaState(LuaState&& instance) noexcept; ~LuaState() = default; void ArgCheck(bool condition, unsigned int argNum, const char* error) const; @@ -174,7 +174,7 @@ namespace Nz void* ToUserdata(int index, const String& tname) const; LuaState& operator=(const LuaState&) = default; - LuaState& operator=(LuaState&& instance) noexcept; + inline LuaState& operator=(LuaState&& instance) noexcept; static int GetIndexOfUpValue(int upValue); static LuaInstance& GetInstance(lua_State* internalState); diff --git a/include/Nazara/Lua/LuaState.inl b/include/Nazara/Lua/LuaState.inl index a5fa57f8c..653198a2b 100644 --- a/include/Nazara/Lua/LuaState.inl +++ b/include/Nazara/Lua/LuaState.inl @@ -20,6 +20,13 @@ namespace Nz { } + inline LuaState::LuaState(LuaState&& state) noexcept : + m_lastError(state.m_lastError), + m_state(state.m_state) + { + state.m_state = nullptr; + } + inline lua_State* LuaState::GetInternalState() const { return m_state; @@ -770,6 +777,16 @@ namespace Nz SetMetatable(tname); } + inline LuaState& LuaState::operator=(LuaState&& state) noexcept + { + m_lastError = std::move(state.m_lastError); + m_state = state.m_state; + + state.m_state = nullptr; + + return *this; + } + template std::enable_if_t::value, T> LuaState::CheckBounds(int index, long long value) const { diff --git a/src/Nazara/Lua/LuaState.cpp b/src/Nazara/Lua/LuaState.cpp index 4821b1d09..e721976bf 100644 --- a/src/Nazara/Lua/LuaState.cpp +++ b/src/Nazara/Lua/LuaState.cpp @@ -126,12 +126,6 @@ namespace Nz static_assert(sizeof(s_types)/sizeof(int) == LuaType_Max+1, "Lua type array is incomplete"); } - LuaState::LuaState(LuaState&& state) noexcept : - m_lastError(state.m_lastError), - m_state(state.m_state) - { - } - void LuaState::ArgCheck(bool condition, unsigned int argNum, const char* error) const { luaL_argcheck(m_state, condition, argNum, error); @@ -789,14 +783,6 @@ namespace Nz return luaL_testudata(m_state, index, tname.GetConstBuffer()); } - LuaState& LuaState::operator=(LuaState&& state) noexcept - { - m_lastError = std::move(state.m_lastError); - m_state = state.m_state; - - return *this; - } - bool LuaState::Run(int argCount, int resultCount) { LuaInstance& instance = GetInstance(m_state);