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/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 <map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace icinga
|
||||
@ -187,6 +189,18 @@ public:
|
||||
ExpressionResult res = expression->Evaluate(frame);
|
||||
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>()) {
|
||||
if (fvvar.IsEmpty())
|
||||
BOOST_THROW_EXCEPTION(ScriptError("Cannot use array iterator for dictionary.", debugInfo));
|
||||
|
Loading…
x
Reference in New Issue
Block a user