Switching .at and [], added out of bounds exception

This commit is contained in:
Jonathan Turner 2009-06-10 23:32:32 +00:00
parent 4d56cffb26
commit da60cad358
2 changed files with 5 additions and 2 deletions

View File

@ -16,9 +16,9 @@ void bootstrap_random_access_container(BoxedCPP_System &system, const std::strin
typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);
system.register_function(
boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::operator[])), "[]");
boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::at)), "[]");
system.register_function(
boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::at)), "at");
boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::operator[])), "at");
}
template<typename Assignable>

View File

@ -131,6 +131,9 @@ Boxed_Value eval_token(Eval_System &ss, TokenPtr node) {
try {
retval = dispatch(ss.get_function("[]"), plb);
}
catch(std::out_of_range &oor) {
throw EvalError("Out of bounds exception", node);
}
catch(std::exception &e){
throw EvalError("Can not find appropriate array lookup '[]'", node->children[i]);
}