Operators
As in all programming and scripting languages, operators in AviSynth script language allow the performance of actions (operations) on variables. Operators form the basis for building expressions, the building blocks of AviSynth grammar.
AviSynth operators follow loosely the same rules as C operators, regarding meaning, precedence and associativity. By 'loosely', we mean that there are some exceptions, indicated below.
Note that as in C, when a binary operator is applied to an int and a float, the int is automatically converted to float prior to the operation.
Contents |
For All Variable Types
For all types of operands (clip, int, float, string, bool) you can use the following operators:
Operator Meaning == is equal != not equal <> not equal
string comparisons are not case-sensitive, so "abc" == "ABC" returns true.
Note comparisons may be chained:
(3 <= x <= 5)
can be used where normally something like(3 <= x && x <= 5)
would be required.(doom9)
For Numbers
For numeric types (int, float) you can use the following numeric-specific operators:
Operator Meaning + add - subtract * multiply / divide % mod >= greater or equal than <= less or equal than < less than > greater than
For Strings
For string type you can use the following string-specific operators:
Operator Meaning + concatenate >= greater or equal than <= less or equal than < less than > greater than
Like the equality operator, these string comparisons are case-insensitive.
For Clips
For clip type you can use the following clip-specific operators:
Operator Meaning + same as the function UnalignedSplice ++ same as the function AlignedSplice
For Booleans
For bool type (true/false) you can use the following bool-specific operators:
Operator Meaning || or && and ?: ternary (conditional execution) operator ! not
The ternary (conditional execution) operator is used as in the following example:
b = (a==true) ? 1 : 2
This means, in pseudocode:
if (a==true) then b=1 else b=2
AviSynth provides a NOP function for cases where the else clause is not needed (such as a conditional Import or LoadPlugin).
Operator Precedence
The precedence of AviSynth operators is presented at the table below. Operators in the same row have the same precedence.
highest: * / % + ++ - < > <= >= != <> == && || lowest: ?:
The dot [.] symbol ("OOP notation" for a function call, where a.function(b)
is equivalent to function(a, b)
) has a higher precedence than any operator – for example,
a*b.function(c)
is equivalent to
a*function(b, c)
but since parentheses override normal precedence,
(a*b).function(c)
is equivalent to
function(a*b, c)
</div>
Back to AviSynth Syntax.