diff --git a/src/catalua_impl.cpp b/src/catalua_impl.cpp index 8136449ffa0e..63d881df295b 100644 --- a/src/catalua_impl.cpp +++ b/src/catalua_impl.cpp @@ -7,6 +7,8 @@ #include "debug.h" #include "string_formatter.h" +#include +#include #include #include @@ -182,9 +184,20 @@ bool compare_values( sol::object a, sol::object b ) if( type == sol::type::thread ) { throw std::runtime_error( "Can't compare threads" ); } - if( type == sol::type::number && - is_number_integer( lua, a ) != is_number_integer( lua, b ) - ) { + if( type == sol::type::number ) { + if( is_number_integer( lua, a ) != is_number_integer( lua, b ) ) { + return false; + } + if( is_number_integer( lua, a ) ) { + int num_a = a.as(); + int num_b = b.as(); + return num_a == num_b; + } else { + double num_a = a.as(); + double num_b = b.as(); + // FIXME: not suitable for all cases + return std::fabs( num_a - num_b ) < 0.0001; + } return false; } if( type == sol::type::userdata ) {