From a294546bcc7c883edd113f2c80d7f278ff8219ed Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 29 Nov 2018 22:45:16 -0800 Subject: Improved type safety of flag enums --- RenderScript/include/LuaBindings.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'RenderScript/include/LuaBindings.h') diff --git a/RenderScript/include/LuaBindings.h b/RenderScript/include/LuaBindings.h index e43b9a3..a09e1d0 100644 --- a/RenderScript/include/LuaBindings.h +++ b/RenderScript/include/LuaBindings.h @@ -461,7 +461,7 @@ namespace Diligent BindingsMap.insert( std::make_pair( #Member, std::unique_ptr(pNewBinder) ) ); \ }while(false) - template< typename EnumType, typename FlagsType = Uint32 > + template< typename EnumType, typename FlagsType = std::underlying_type::type > class FlagsLoader : public MemberBinderBase { public: @@ -478,7 +478,7 @@ namespace Diligent int ArrayInd = 1; for( auto it = m_EnumMapping.m_Val2StrMap.begin(); it != m_EnumMapping.m_Val2StrMap.end(); ++it ) { - if( static_cast(Flags & it->first) == it->first ) + if( it->first != 0 && static_cast(Flags & it->first) == it->first || Flags == 0 && it->first == 0) { lua_pushnumber( L, ArrayInd ); // -0 | +1 -> +1 PushValue( L, it->second ); // -0 | +1 -> +1 @@ -490,7 +490,7 @@ namespace Diligent virtual void SetValue( lua_State *L, int Index, void* pBasePointer ) { - FlagsType Flags = 0; + FlagsType Flags = static_cast(0); if( lua_isnumber( L, Index ) ) { Flags = static_cast( ReadValueFromLua( L, Index ) ); @@ -528,7 +528,7 @@ namespace Diligent { String AllowableValues = GetEnumMappingsString( m_EnumMapping ); SCRIPT_PARSING_ERROR( L, "Unknown flag (\"", CurrFlagName, "\") provided for parameter ", m_MemberName, ". Only the following flags are allowed:\n", AllowableValues ); - return 0; + return static_cast(0); } } -- cgit v1.2.3