mirror of https://github.com/Icinga/icinga2.git
parent
9adc63737a
commit
1aca29afd2
|
@ -223,65 +223,67 @@ In this example a has the value 7 after both instructions are executed.
|
|||
|
||||
#### <a id="operator-additive-assignment"></a> Operator +=
|
||||
|
||||
Modifies a dictionary or array by adding new elements to it.
|
||||
|
||||
Example:
|
||||
The += operator is a shortcut. The following expression:
|
||||
|
||||
{
|
||||
a = [ "hello" ],
|
||||
a += [ "world" ]
|
||||
}
|
||||
|
||||
In this example a contains both `"hello"` and `"world"`. This currently
|
||||
only works for dictionaries and arrays.
|
||||
is equivalent to:
|
||||
|
||||
<!--
|
||||
{
|
||||
a = [ "hello" ],
|
||||
a = a + [ "world" ]
|
||||
}
|
||||
|
||||
#### <a id="operator-substractive-assignment"></a> Operator -=
|
||||
|
||||
Removes elements from a dictionary.
|
||||
|
||||
Example:
|
||||
The -= operator is a shortcut. The following expression:
|
||||
|
||||
{
|
||||
a = { "hello", "world" },
|
||||
a -= [ "world" ]
|
||||
a = 10,
|
||||
a -= 5
|
||||
}
|
||||
|
||||
In this example a contains `"hello"`. Trying to remove an item that does
|
||||
not exist is not an error. Not implemented yet.
|
||||
is equivalent to:
|
||||
|
||||
{
|
||||
a = 10,
|
||||
a = a - 5
|
||||
}
|
||||
|
||||
#### <a id="operator-multiply-assignment"></a> Operator \*=
|
||||
|
||||
Multiplies an existing dictionary element with the specified number. If
|
||||
the dictionary element does not already exist 0 is used as its value.
|
||||
|
||||
Example:
|
||||
The *= operator is a shortcut. The following expression:
|
||||
|
||||
{
|
||||
a = 60,
|
||||
a *= 5
|
||||
}
|
||||
|
||||
In this example a is 300. This only works for numbers. Not implemented
|
||||
yet.
|
||||
is equivalent to:
|
||||
|
||||
{
|
||||
a = 60,
|
||||
a = a * 5
|
||||
}
|
||||
|
||||
#### <a id="operator-dividing-assignment"></a> Operator /=
|
||||
|
||||
Divides an existing dictionary element by the specified number. If the
|
||||
dictionary element does not already exist 0 is used as its value.
|
||||
|
||||
Example:
|
||||
The /= operator is a shortcut. The following expression:
|
||||
|
||||
{
|
||||
a = 300,
|
||||
a /= 5
|
||||
}
|
||||
|
||||
In this example a is 60. This only works for numbers. Not implemented
|
||||
yet.
|
||||
is equivalent to:
|
||||
|
||||
-->
|
||||
{
|
||||
a = 300,
|
||||
a = a / 5
|
||||
}
|
||||
|
||||
### <a id="indexer"></a> Indexer
|
||||
|
||||
|
|
|
@ -397,5 +397,9 @@ Value AExpression::OpSetDivide(const AExpression *expr, const Dictionary::Ptr& l
|
|||
Value AExpression::OpIndexer(const AExpression *expr, const Dictionary::Ptr& locals)
|
||||
{
|
||||
Dictionary::Ptr dict = locals->Get(expr->m_Operand1);
|
||||
|
||||
if (!dict)
|
||||
BOOST_THROW_EXCEPTION(ConfigError("Script variable '" + expr->m_Operand1 + "' not set in this scope."));
|
||||
|
||||
return dict->Get(expr->m_Operand2);
|
||||
}
|
||||
|
|
|
@ -547,9 +547,6 @@ lterm_items_inner: /* empty */
|
|||
lterm: identifier lbinary_op rterm
|
||||
{
|
||||
AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$3);
|
||||
if ($2 == &AExpression::OpSetPlus || $2 == &AExpression::OpSetMinus || $2 == &AExpression::OpSetMultiply || $2 == &AExpression::OpSetDivide)
|
||||
aexpr->MakeInline();
|
||||
|
||||
$$ = new Value(make_shared<AExpression>($2, $1, aexpr, DebugInfoRange(@1, @3)));
|
||||
free($1);
|
||||
delete $3;
|
||||
|
@ -564,9 +561,6 @@ lterm: identifier lbinary_op rterm
|
|||
subexprl->Add(subexpr);
|
||||
|
||||
AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6));
|
||||
if ($5 == &AExpression::OpSetPlus || $5 == &AExpression::OpSetMinus || $5 == &AExpression::OpSetMultiply || $5 == &AExpression::OpSetDivide)
|
||||
expr->MakeInline();
|
||||
|
||||
$$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @6)));
|
||||
free($1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue