Fix numeric mixed-convesion operations
This commit is contained in:
parent
cefb4d3c78
commit
4b81a24a0a
@ -846,7 +846,8 @@ namespace chaiscript
|
||||
plist.begin(),
|
||||
std::back_inserter(newplist),
|
||||
[](const Type_Info &ti, const Boxed_Value ¶m) -> 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;
|
||||
} else {
|
||||
return param;
|
||||
@ -854,8 +855,6 @@ namespace chaiscript
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
try {
|
||||
return (*(matching_func->second))(newplist, t_conversions);
|
||||
} catch (const exception::bad_boxed_cast &) {
|
||||
|
@ -60,6 +60,16 @@ namespace chaiscript
|
||||
return m_type_info < ti.m_type_info;
|
||||
}
|
||||
|
||||
CHAISCRIPT_CONSTEXPR bool operator!=(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||
{
|
||||
return !(operator==(ti));
|
||||
}
|
||||
|
||||
CHAISCRIPT_CONSTEXPR bool operator!=(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT
|
||||
{
|
||||
return !(operator==(ti));
|
||||
}
|
||||
|
||||
CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||
{
|
||||
return ti.m_type_info == m_type_info
|
||||
|
@ -950,4 +950,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);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user