Documentation |
## Documentation.Script-Operators-2-2 HistoryHide minor edits - Show changes to markup November 28, 2016, at 11:29 AM
by
- Changed line 1 from:
## Documentation -> Manuals -> Manual devel -> Script Operatorsto:
## Documentation -> Manuals -> Manual 2.2 -> Script OperatorsMarch 20, 2014, at 08:28 PM
by
- Added lines 1-73:
## Documentation -> Manuals -> Manual devel -> Script Operators(:title Script Operators - 2.2:) (:allVersions Script-Operators 2.2:)
(:toc-float Table of Content:) Assignments, string and arithmetic operations can be done directly in the configuration file. ## AssignmentAssignments can be done like in C, via '=' (equal) operator. Not that not all variables (from script) can be written, some are read-only. Check with listing of variables to see which ones can be written too. $var(a) = 123; $ru = "sip:user@domain"; There is a special assign operator ':=' (colon equal) that can be used with AVPs. If the right value is $avp(val) := 123; ## String operationsFor strings, '+' is available to concatenate. $var(a) = "test"; $var(b) = "sip:" + $var(a) + "@" + $fd; ## Arithmetic and bitwise operationsFor numbers, one can use: - + : plus
- - : minus
- / : divide
- * : multiply
- % : modulo
- | : bitwise OR
- & : bitwise AND
- ^ : bitwise XOR
- ~ : bitwise NOT
- << : bitwise left shift
- >> : bitwise right shift
Example: $var(a) = 4 + ( 7 & ( ~2 ) ); NOTE: to ensure the priority of operands in expression evaluations do use __parenthesis__. Arithmetic expressions can be used in condition expressions via test operator ' [ ... ] '. if( [ $var(a) & 4 ] ) log("var a has third bit set\n"); |