From: Gunnar Beutner Date: Wed, 2 Apr 2014 07:04:49 +0000 (+0200) Subject: Allow functions to return values. X-Git-Tag: v0.0.10~235 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41d0dde52ec5ed4071ef31aaf24b458edc98077b;p=icinga2 Allow functions to return values. Fixes #5922 --- diff --git a/lib/config/aexpression.cpp b/lib/config/aexpression.cpp index 7f1f51b19..cbecdb4c0 100644 --- a/lib/config/aexpression.cpp +++ b/lib/config/aexpression.cpp @@ -475,7 +475,8 @@ Value AExpression::FunctionWrapper(const std::vector& arguments, const Ar for (int i = 0; i < std::min(arguments.size(), funcargs->GetLength()); i++) locals->Set(funcargs->Get(i), arguments[i]); - return expr->Evaluate(locals); + expr->Evaluate(locals); + return locals->Get("__result"); } Value AExpression::OpFunction(const AExpression* expr, const Dictionary::Ptr& locals) diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 4a56e2005..7e3f520b6 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -781,8 +781,12 @@ rterm: T_STRING arr->Add(Empty); - arr->Add(*$4); + Array::Ptr arrex = make_shared(); + arrex->Add(make_shared(&AExpression::OpSet, make_shared(&AExpression::OpLiteral, "__result", @4), *$4, @4)); delete $4; + AExpression::Ptr aexpr = make_shared(&AExpression::OpDict, arrex, true, @4); + + arr->Add(aexpr); $$ = new Value(make_shared(&AExpression::OpFunction, arr, Array::Ptr($2), DebugInfoRange(@1, @4))); }