From 8a6a46d0d35eb7033c6ae43445287afa047ecfe0 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 29 Aug 2010 19:49:57 +0000 Subject: [PATCH] Fix to the method/array dispatch issue --- .../chaiscript/language/chaiscript_eval.hpp | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 7598f32..00cd7fa 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -804,13 +804,13 @@ namespace chaiscript std::string fun_name; std::vector > funs; - if (this->children[i]->identifier == AST_Node_Type::Fun_Call) { + if ((this->children[i]->identifier == AST_Node_Type::Fun_Call) || (this->children[i]->identifier == AST_Node_Type::Array_Call)) { fun_name = this->children[i]->children[0]->text; } else { fun_name = this->children[i]->text; } - + try { ss.set_stack(new_stack); retval = ss.call_function(fun_name, plb); @@ -828,6 +828,23 @@ namespace chaiscript ss.set_stack(prev_stack); throw; } + if (this->children[i]->identifier == AST_Node_Type::Array_Call) { + for (unsigned int j = 1; j < this->children[i]->children.size(); ++j) { + try { + retval = ss.call_function("[]", retval, this->children[i]->children[j]->eval(ss)); + } + catch(std::out_of_range &) { + throw Eval_Error("Out of bounds exception"); + } + catch(const dispatch_error &){ + throw Eval_Error("Can not find appropriate array lookup '[]' "); + } + catch(Eval_Error &ee) { + ee.call_stack.push_back(this->children[i]->children[j]); + throw; + } + } + } } }