diff --git a/boxedcpp/boxedcpp.hpp b/boxedcpp/boxedcpp.hpp index 589b20e..e082297 100644 --- a/boxedcpp/boxedcpp.hpp +++ b/boxedcpp/boxedcpp.hpp @@ -45,11 +45,17 @@ class BoxedCPP_System template void set_object(const std::string &name, const Class &obj) { - try { - get_object(name) = Boxed_Value(obj); - } catch (const std::range_error &) { - add_object(name, obj); + for (int i = m_scopes.size()-1; i >= 0; --i) + { + std::map::const_iterator itr = m_scopes[i].find(name); + if (itr != m_scopes[i].end()) + { + m_scopes[i][name] = Boxed_Value(obj); + return; + } } + + add_object(name, obj); } template @@ -75,7 +81,7 @@ class BoxedCPP_System Boxed_Value get_object(const std::string &name) const { - for (size_t i = m_scopes.size()-1; i >= 0; --i) + for (int i = m_scopes.size()-1; i >= 0; --i) { std::map::const_iterator itr = m_scopes[i].find(name); if (itr != m_scopes[i].end()) diff --git a/wesley/main.cpp b/wesley/main.cpp index 745112c..34623e3 100644 --- a/wesley/main.cpp +++ b/wesley/main.cpp @@ -150,7 +150,7 @@ Boxed_Value eval_token(BoxedCPP_System &ss, TokenPtr node) { if (node->children.size() > 1) { for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) { if (node->children[i+1]->text == "=") { - ss.add_object(node->children[i]->text, retval); + ss.set_object(node->children[i]->text, retval); } else { Param_List_Builder plb;