Merge branch 'release-5.x' into develop

This commit is contained in:
Jason Turner
2016-10-05 15:14:58 -06:00
4 changed files with 34 additions and 5 deletions

View File

@@ -819,7 +819,8 @@ namespace chaiscript
plist.begin(), plist.begin(),
std::back_inserter(newplist), std::back_inserter(newplist),
[](const Type_Info &ti, const Boxed_Value &param) -> Boxed_Value { [](const Type_Info &ti, const Boxed_Value &param) -> Boxed_Value {
if (ti.is_arithmetic() && param.get_type_info().is_arithmetic()) { if (ti.is_arithmetic() && param.get_type_info().is_arithmetic()
&& param.get_type_info() != ti) {
return Boxed_Number(param).get_as(ti).bv; return Boxed_Number(param).get_as(ti).bv;
} else { } else {
return param; return param;
@@ -827,8 +828,6 @@ namespace chaiscript
} }
); );
try { try {
return (*(matching_func->second))(newplist, t_conversions); return (*(matching_func->second))(newplist, t_conversions);
} catch (const exception::bad_boxed_cast &) { } catch (const exception::bad_boxed_cast &) {

View File

@@ -47,6 +47,16 @@ namespace chaiscript
return m_type_info < ti.m_type_info; return m_type_info < ti.m_type_info;
} }
constexpr bool operator!=(const Type_Info &ti) const noexcept
{
return !(operator==(ti));
}
constexpr bool operator!=(const std::type_info &ti) const noexcept
{
return !(operator==(ti));
}
constexpr bool operator==(const Type_Info &ti) const noexcept constexpr bool operator==(const Type_Info &ti) const noexcept
{ {
return ti.m_type_info == m_type_info return ti.m_type_info == m_type_info

View File

@@ -38,8 +38,8 @@ Current Version: 6.0.0
* File location tracking has been rewritten; this currently means error location reporting is not as good as it was * File location tracking has been rewritten; this currently means error location reporting is not as good as it was
* Tracing capability needs to be tested and vetted * Tracing capability needs to be tested and vetted
### Changes since 5.8.3
* Fix case with some numeric conversions mixed with numerics that do not need conversion
### Changes since 5.8.2 ### Changes since 5.8.2
* Add support for reference of pointer return types * Add support for reference of pointer return types

View File

@@ -952,4 +952,24 @@ TEST_CASE("Parse floats with non-posix locale")
bool FindBitmap(int &ox, int &oy, long) {
ox = 1;
oy = 2;
return true;
}
TEST_CASE("Mismatched numeric types only convert necessary params")
{
chaiscript::ChaiScript chai;
chai.add(chaiscript::fun(&FindBitmap), "FindBitmap");
int x = 0;
int y = 0;
chai.add(chaiscript::var(&x), "x");
chai.add(chaiscript::var(&y), "y");
chai.eval( "if ( FindBitmap ( x, y, 0) ) { print(\"found at \" + to_string(x) + \", \" + to_string(y))}" );
CHECK(x == 1);
CHECK(y == 2);
}