From c4ce4010d140b243481bc22eb80f852d92867f8b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 28 Jan 2020 10:14:11 +0100 Subject: [PATCH] Allow to iterate over generators --- lib/config/vmops.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index ea3098359..6d6e840b6 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -11,6 +11,7 @@ #include "base/debuginfo.hpp" #include "base/array.hpp" #include "base/dictionary.hpp" +#include "base/generator.hpp" #include "base/namespace.hpp" #include "base/function.hpp" #include "base/scriptglobal.hpp" @@ -18,6 +19,7 @@ #include "base/convert.hpp" #include "base/objectlock.hpp" #include +#include #include namespace icinga @@ -187,6 +189,18 @@ public: ExpressionResult res = expression->Evaluate(frame); CHECK_RESULT_LOOP(res); } + } else if (value.IsObjectType()) { + if (!fvvar.IsEmpty()) + BOOST_THROW_EXCEPTION(ScriptError("Cannot use dictionary iterator for generator.", debugInfo)); + + Generator::Ptr gen = value; + Value buf; + + while (gen->GetNext(buf)) { + frame.Locals->Set(fkvar, std::move(buf)); + ExpressionResult res = expression->Evaluate(frame); + CHECK_RESULT_LOOP(res); + } } else if (value.IsObjectType()) { if (fvvar.IsEmpty()) BOOST_THROW_EXCEPTION(ScriptError("Cannot use array iterator for dictionary.", debugInfo));