diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp index d5887d387a..e30b7f3ba2 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp @@ -199,8 +199,8 @@ int CLuaDrawingDefs::DxDrawLine3D(lua_State* luaVM) argStream.ReadVector3D(vecEnd); argStream.ReadColor(color, 0xFFFFFFFF); argStream.ReadNumber(fWidth, 1); - if (bool bPostGUI = argStream.ReadIfNextIsBool()) - renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX; + if (argStream.NextIsBool()) + renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX; else argStream.ReadIfNextIsEnumString(renderStage, eRenderStage::POST_FX); @@ -240,8 +240,8 @@ int CLuaDrawingDefs::DxDrawMaterialLine3D(lua_State* luaVM) argStream.ReadUserData(pMaterial); argStream.ReadNumber(fWidth); argStream.ReadColor(color, 0xFFFFFFFF); - if (bool bPostGUI = argStream.ReadIfNextIsBool()) - renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX; + if (argStream.NextIsBool()) + renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX; else argStream.ReadIfNextIsEnumString(renderStage, eRenderStage::POST_FX); @@ -292,10 +292,11 @@ int CLuaDrawingDefs::DxDrawMaterialSectionLine3D(lua_State* luaVM) argStream.ReadUserData(pMaterial); argStream.ReadNumber(fWidth); argStream.ReadColor(color, 0xFFFFFFFF); - if (bool bPostGUI = argStream.ReadIfNextIsBool()) - renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX; + if (argStream.NextIsBool()) + renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX; else argStream.ReadIfNextIsEnumString(renderStage, eRenderStage::POST_FX); + if (argStream.NextIsVector3D()) { argStream.ReadVector3D(vecFaceToward); @@ -599,8 +600,8 @@ int CLuaDrawingDefs::DxDrawPrimitive3D(lua_State* luaVM) eRenderStage renderStage{eRenderStage::POST_FX}; CScriptArgReader argStream(luaVM); argStream.ReadEnumString(ePrimitiveType); - if (bool bPostGUI = argStream.ReadIfNextIsBool()) - renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX; + if (argStream.NextIsBool()) + renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX; else argStream.ReadEnumString(renderStage, eRenderStage::POST_FX); @@ -654,8 +655,8 @@ int CLuaDrawingDefs::DxDrawMaterialPrimitive3D(lua_State* luaVM) CScriptArgReader argStream(luaVM); argStream.ReadEnumString(ePrimitiveType); MixedReadMaterialString(argStream, pMaterialElement); - if (bool bPostGUI = argStream.ReadIfNextIsBool()) - renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX; + if (argStream.NextIsBool()) + renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX; else argStream.ReadEnumString(renderStage, eRenderStage::POST_FX); diff --git a/Shared/sdk/CScriptArgReader.h b/Shared/sdk/CScriptArgReader.h index d02eda348c..de54d98cb1 100644 --- a/Shared/sdk/CScriptArgReader.h +++ b/Shared/sdk/CScriptArgReader.h @@ -525,6 +525,22 @@ class CScriptArgReader m_iIndex++; } + // + // Read next bool or false if failed + // Intended for use in pair with NextIsBool() + // + bool ReadBool() + { + int iArgument = lua_type(m_luaVM, m_iIndex); + if (iArgument == LUA_TBOOLEAN) + { + return lua_toboolean(m_luaVM, m_iIndex++) ? true : false; + } + + m_iIndex++; + return false; + } + // // Read next bool, using default if needed // @@ -1331,14 +1347,6 @@ class CScriptArgReader bOutValue = bDefaultValue; } - bool ReadIfNextIsBool(const bool bDefaultValue = false) - { - bool bOutValue{bDefaultValue}; - if (NextIsBool()) - ReadBool(bOutValue, bDefaultValue); - return bOutValue; - } - template void ReadIfNextIsUserData(T*& outValue, T* defaultValue) {