mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-22 17:28:02 +02:00
Allow to iterate over generators
This commit is contained in:
parent
cbd94e060d
commit
c4ce4010d1
@ -11,6 +11,7 @@
|
|||||||
#include "base/debuginfo.hpp"
|
#include "base/debuginfo.hpp"
|
||||||
#include "base/array.hpp"
|
#include "base/array.hpp"
|
||||||
#include "base/dictionary.hpp"
|
#include "base/dictionary.hpp"
|
||||||
|
#include "base/generator.hpp"
|
||||||
#include "base/namespace.hpp"
|
#include "base/namespace.hpp"
|
||||||
#include "base/function.hpp"
|
#include "base/function.hpp"
|
||||||
#include "base/scriptglobal.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
@ -18,6 +19,7 @@
|
|||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
@ -187,6 +189,18 @@ public:
|
|||||||
ExpressionResult res = expression->Evaluate(frame);
|
ExpressionResult res = expression->Evaluate(frame);
|
||||||
CHECK_RESULT_LOOP(res);
|
CHECK_RESULT_LOOP(res);
|
||||||
}
|
}
|
||||||
|
} else if (value.IsObjectType<Generator>()) {
|
||||||
|
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<Dictionary>()) {
|
} else if (value.IsObjectType<Dictionary>()) {
|
||||||
if (fvvar.IsEmpty())
|
if (fvvar.IsEmpty())
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Cannot use array iterator for dictionary.", debugInfo));
|
BOOST_THROW_EXCEPTION(ScriptError("Cannot use array iterator for dictionary.", debugInfo));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user