| 54 | /// Helper function that will set up the scope around a function call, including handling the named function parameters |
| 55 | template<typename T> |
| 56 | static Boxed_Value eval_function(chaiscript::detail::Dispatch_Engine &t_ss, const AST_Node_Impl<T> &t_node, const std::vector<std::string> &t_param_names, const std::vector<Boxed_Value> &t_vals, const std::map<std::string, Boxed_Value> *t_locals=nullptr, bool has_this_capture = false) { |
| 57 | chaiscript::detail::Dispatch_State state(t_ss); |
| 58 | |
| 59 | const Boxed_Value *thisobj = [&]() -> const Boxed_Value *{ |
| 60 | auto &stack = t_ss.get_stack_data(state.stack_holder()).back(); |
| 61 | if (!stack.empty() && stack.back().first == "__this") { |
| 62 | return &stack.back().second; |
| 63 | } else if (!t_vals.empty()) { |
| 64 | return &t_vals[0]; |
| 65 | } else { |
| 66 | return nullptr; |
| 67 | } |
| 68 | }(); |
| 69 | |
| 70 | chaiscript::eval::detail::Stack_Push_Pop tpp(state); |
| 71 | if (thisobj && !has_this_capture) { state.add_object("this", *thisobj); } |
| 72 | |
| 73 | if (t_locals) { |
| 74 | for (const auto &local : *t_locals) { |
| 75 | state.add_object(local.first, local.second); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | for (size_t i = 0; i < t_param_names.size(); ++i) { |
| 80 | if (t_param_names[i] != "this") { |
| 81 | state.add_object(t_param_names[i], t_vals[i]); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | try { |
| 86 | return t_node.eval(state); |
| 87 | } catch (detail::Return_Value &rv) { |
| 88 | return std::move(rv.retval); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | inline Boxed_Value clone_if_necessary(Boxed_Value incoming, std::atomic_uint_fast32_t &t_loc, const chaiscript::detail::Dispatch_State &t_ss) |
| 93 | { |
no test coverage detected