diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 795bac8f..4c082d63 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -296,19 +296,15 @@ namespace chaiscript public: + Boxed_Number() + : bv(Boxed_Value(0)) + { + } + Boxed_Number(const Boxed_Value &v) : bv(v) { - const Type_Info &inp_ = v.get_type_info(); - if (inp_ == typeid(bool)) - { - throw chaiscript::detail::exception::bad_any_cast(); - } - - if (!inp_.is_arithmetic()) - { - throw chaiscript::detail::exception::bad_any_cast(); - } + validate_boxed_number(v); } @@ -377,6 +373,27 @@ namespace chaiscript return oper(Operators::assign_bitwise_and, this->bv, t_rhs.bv); } + void validate_boxed_number(const Boxed_Value &v) + { + const Type_Info &inp_ = v.get_type_info(); + if (inp_ == typeid(bool)) + { + throw chaiscript::detail::exception::bad_any_cast(); + } + + if (!inp_.is_arithmetic()) + { + throw chaiscript::detail::exception::bad_any_cast(); + } + } + + Boxed_Number operator=(const Boxed_Value &v) + { + validate_boxed_number(v); + bv = v; + return *this; + } + Boxed_Number operator=(const Boxed_Number &t_rhs) const { return oper(Operators::assign, this->bv, t_rhs.bv); diff --git a/samples/example.cpp b/samples/example.cpp index 9319d187..e5838b08 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -165,7 +165,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //Dynamic objects test chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world"); chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType"); - chai.add(fun(std::function(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", std::placeholders::_1))), "attr"); +// chai.add(fun(std::function(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", std::placeholders::_1))), "attr"); chai.eval("var x = TestType()"); // chai.eval("x.attr = \"hi\"");