From 92bfcfdcf31838274fa08e1585abc65d4fc84472 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 31 May 2011 09:38:04 +0800 Subject: [PATCH] Wrap up new Boxed_Numeric support --- include/chaiscript/dispatchkit/bootstrap.hpp | 1 + include/chaiscript/dispatchkit/boxed_numeric.hpp | 8 ++++++-- unittests/boxed_cast_test.cpp | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index b191892..5f62237 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -429,6 +429,7 @@ namespace chaiscript basic_constructors("bool", m); operators::assign(m); + operators::equal(m); m->add(fun(&to_string), "internal_to_string"); m->add(fun(&Bootstrap::bool_to_string), "internal_to_string"); diff --git a/include/chaiscript/dispatchkit/boxed_numeric.hpp b/include/chaiscript/dispatchkit/boxed_numeric.hpp index 4527579..52700e8 100644 --- a/include/chaiscript/dispatchkit/boxed_numeric.hpp +++ b/include/chaiscript/dispatchkit/boxed_numeric.hpp @@ -46,9 +46,9 @@ namespace chaiscript assign_shift_right, assign_remainder, assign_bitwise_xor, + const_int_flag, shift_left, shift_right, - const_int_flag, remainder, bitwise_and, bitwise_or, @@ -321,7 +321,7 @@ namespace chaiscript return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::uint64_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); - } else { + } else { throw boost::bad_any_cast(); } } @@ -333,6 +333,10 @@ namespace chaiscript : bv(v) { const Type_Info &inp_ = v.get_type_info(); + if (inp_ == typeid(bool)) + { + throw boost::bad_any_cast(); + } if (!inp_.is_arithmetic()) { diff --git a/unittests/boxed_cast_test.cpp b/unittests/boxed_cast_test.cpp index ca53707..078ec97 100644 --- a/unittests/boxed_cast_test.cpp +++ b/unittests/boxed_cast_test.cpp @@ -301,7 +301,9 @@ int main() passed &= built_in_type_test(5, true); passed &= built_in_type_test(1.1, true); passed &= built_in_type_test('a', true); - passed &= built_in_type_test(false, true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test(false, false); passed &= built_in_type_test("Hello World", false); // storing a pointer