Wrap up new Boxed_Numeric support

This commit is contained in:
Jason Turner
2011-05-31 09:38:04 +08:00
committed by Jason Turner
parent 3b754cfec4
commit 92bfcfdcf3
3 changed files with 10 additions and 3 deletions

View File

@@ -429,6 +429,7 @@ namespace chaiscript
basic_constructors<bool>("bool", m); basic_constructors<bool>("bool", m);
operators::assign<bool>(m); operators::assign<bool>(m);
operators::equal<bool>(m);
m->add(fun(&to_string<const std::string &>), "internal_to_string"); m->add(fun(&to_string<const std::string &>), "internal_to_string");
m->add(fun(&Bootstrap::bool_to_string), "internal_to_string"); m->add(fun(&Bootstrap::bool_to_string), "internal_to_string");

View File

@@ -46,9 +46,9 @@ namespace chaiscript
assign_shift_right, assign_shift_right,
assign_remainder, assign_remainder,
assign_bitwise_xor, assign_bitwise_xor,
const_int_flag,
shift_left, shift_left,
shift_right, shift_right,
const_int_flag,
remainder, remainder,
bitwise_and, bitwise_and,
bitwise_or, bitwise_or,
@@ -321,7 +321,7 @@ namespace chaiscript
return oper_rhs<boost::uint32_t, false>(t_oper, t_lhs, t_rhs); return oper_rhs<boost::uint32_t, false>(t_oper, t_lhs, t_rhs);
} else if (inp_ == typeid(boost::uint64_t)) { } else if (inp_ == typeid(boost::uint64_t)) {
return oper_rhs<boost::uint64_t, false>(t_oper, t_lhs, t_rhs); return oper_rhs<boost::uint64_t, false>(t_oper, t_lhs, t_rhs);
} else { } else {
throw boost::bad_any_cast(); throw boost::bad_any_cast();
} }
} }
@@ -333,6 +333,10 @@ namespace chaiscript
: bv(v) : bv(v)
{ {
const Type_Info &inp_ = v.get_type_info(); const Type_Info &inp_ = v.get_type_info();
if (inp_ == typeid(bool))
{
throw boost::bad_any_cast();
}
if (!inp_.is_arithmetic()) if (!inp_.is_arithmetic())
{ {

View File

@@ -301,7 +301,9 @@ int main()
passed &= built_in_type_test<int>(5, true); passed &= built_in_type_test<int>(5, true);
passed &= built_in_type_test<double>(1.1, true); passed &= built_in_type_test<double>(1.1, true);
passed &= built_in_type_test<char>('a', true); passed &= built_in_type_test<char>('a', true);
passed &= built_in_type_test<bool>(false, true); passed &= built_in_type_test<uint8_t>('a', true);
passed &= built_in_type_test<int64_t>('a', true);
passed &= built_in_type_test<bool>(false, false);
passed &= built_in_type_test<std::string>("Hello World", false); passed &= built_in_type_test<std::string>("Hello World", false);
// storing a pointer // storing a pointer