Operators
Raffriff42 (Talk | contribs) m (vertical spacing) |
Raffriff42 (Talk | contribs) (formatting, links, phrasing) |
||
Line 1: | Line 1: | ||
− | As in all programming and scripting languages, operators in AviSynth script language allow the performance of actions (operations) | + | <div style="max-width:62em" > |
+ | As in all programming and scripting languages, '''operators''' in AviSynth script language allow the performance of ''actions'' (operations) on [[Script_variables|'''variables''']]. Operators form the basis for building ''expressions'', the building blocks of AviSynth [[Grammar|'''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 | + | AviSynth operators follow loosely the same rules as [[wikipedia:C_(programming_language)|'''C''']] operators, regarding meaning, precedence and associativity. By 'loosely', we mean that there are some exceptions, indicated below. |
− | Note that when a binary operator is applied to an int and a float, the int is | + | Note that as in '''C''', when a [[wikipedia:Binary_operation|binary operator]] is applied to an {{FuncArg|{{FuncArg|int}}}} and a {{FuncArg|float}}, the {{FuncArg|int}} is automatically converted to {{FuncArg|float}} prior to the operation. |
==== For All Variable Types ==== | ==== For All Variable Types ==== | ||
− | For '''all types''' of operands (clip, int, float, string, bool) you can use the following operators: | + | For '''all types''' of operands ({{FuncArg|clip}}, {{FuncArg|int}}, {{FuncArg|float}}, {{FuncArg|string}}, {{FuncArg|bool}}) you can use the following operators: |
− | {| | + | :{|class="wikitable" |
+ | ! Operator | ||
+ | !style="width:23em;text-align:left"| Meaning | ||
+ | |- | ||
| == | | == | ||
| is equal | | is equal | ||
Line 17: | Line 21: | ||
|- | |- | ||
| <> | | <> | ||
− | | not equal | + | | not equal |
|} | |} | ||
− | + | {{FuncArg|string}} comparisons are not case-sensitive, so "abc" == "ABC" returns ''true''. | |
==== For Numbers ==== | ==== For Numbers ==== | ||
− | For '''numeric''' types (int, float) you can use the following | + | For '''numeric''' types ({{FuncArg|int}}, {{FuncArg|float}}) you can use the following numeric-specific operators: |
− | {| | + | :{|class="wikitable" |
+ | !style="width:5em"| Operator | ||
+ | !style="width:23em;text-align:left"| Meaning | ||
+ | |- | ||
| + | | + | ||
| add | | add | ||
Line 54: | Line 61: | ||
| greater than | | greater than | ||
|} | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==== For Strings ==== | ==== For Strings ==== | ||
− | For | + | For {{FuncArg|string}} type you can use the following {{FuncArg|string}}-specific operators: |
− | {| | + | :{|class="wikitable" |
+ | !style="width:5em"| Operator | ||
+ | !style="width:23em;text-align:left"| Meaning | ||
+ | |- | ||
| + | | + | ||
| concatenate | | concatenate | ||
|- | |- | ||
| >= | | >= | ||
− | | greater or equal than | + | | greater or equal than |
|- | |- | ||
| <= | | <= | ||
− | | less or equal than | + | | less or equal than |
|- | |- | ||
| < | | < | ||
− | | less than | + | | less than |
|- | |- | ||
| > | | > | ||
− | | greater than | + | | greater than |
|} | |} | ||
− | Like the equality operator, these string comparisons are case-insensitive. | + | Like the equality operator, these {{FuncArg|string}} comparisons are case-insensitive. |
==== For Clips ==== | ==== For Clips ==== | ||
− | For | + | For {{FuncArg|clip}} type you can use the following {{FuncArg|clip}}-specific operators: |
− | {| | + | :{|class="wikitable" |
+ | !style="width:5em"| Operator | ||
+ | !style="width:23em;text-align:left"| Meaning | ||
+ | |- | ||
| + | | + | ||
− | | | + | | same as the function [[Splice|UnalignedSplice]] |
|- | |- | ||
| ++ | | ++ | ||
− | | | + | | same as the function [[Splice|AlignedSplice]] |
|} | |} | ||
− | + | ||
==== For Booleans ==== | ==== For Booleans ==== | ||
− | For | + | For {{FuncArg|bool}} type (true/false) you can use the following {{FuncArg|bool}}-specific operators: |
− | {| | + | :{|class="wikitable" |
+ | !style="width:5em"| Operator | ||
+ | !style="width:23em;text-align:left"| Meaning | ||
+ | |- | ||
| <nowiki>||</nowiki> | | <nowiki>||</nowiki> | ||
| or | | or | ||
Line 109: | Line 118: | ||
|- | |- | ||
| ?: | | ?: | ||
− | | | + | | ternary (conditional execution) operator |
|- | |- | ||
| ! | | ! | ||
Line 115: | Line 124: | ||
|} | |} | ||
− | The conditional execution operator is used as in the following example: | + | The [[wikipedia:Ternary_operation|'''ternary''']] (conditional execution) operator is used as in the following example: |
− | + | <div {{BoxWidthIndent|29|2}} > | |
b = (a==true) ? 1 : 2 | b = (a==true) ? 1 : 2 | ||
− | + | </div> | |
− | This means in | + | This means, in [[wikipedia:Pseudocode|'''pseudocode''']]: |
− | + | <div {{BoxWidthIndent|29|2}} > | |
− | if (a=true) then b=1 else b=2 | + | '''''if''''' (a==true) '''''then''''' b=1 '''''else''''' b=2 |
− | + | </div> | |
− | + | AviSynth provides a [[Internal_functions#NOP|NOP]] function for cases where the ''else'' clause is not needed (such as a conditional [[Import]] or [[Plugins|LoadPlugin]]). | |
==== Operator Precedence ==== | ==== Operator Precedence ==== | ||
− | The precedence of AviSynth operators is presented at the table below. Operators | + | The [[wikipedia:Order_of_operations|precedence]] of AviSynth operators is presented at the table below. Operators in the same row have the same precedence. |
− | {| | + | :{|class="wikitable" |
− | | * | + | |style="width:5em"| '''highest:''' |
− | | / | + | | * |
− | | % | + | | / |
+ | | % | ||
|colspan=4| | |colspan=4| | ||
|- | |- | ||
− | | + | + | | |
+ | | + | ||
| ++ | | ++ | ||
− | | - | + | | - |
|colspan=4| | |colspan=4| | ||
|- | |- | ||
− | | < | + | | |
− | | > | + | |style="width:1.5em"| < |
− | | <= | + | |style="width:1.5em"| > |
− | | >= | + | |style="width:1.5em"| <= |
− | | != | + | |style="width:1.5em"| >= |
− | | <> | + | |style="width:1.5em"| != |
− | | == | + | |style="width:1.5em"| <> |
+ | |style="width:1.5em"| == | ||
|- | |- | ||
+ | | | ||
| && | | && | ||
|colspan=6| | |colspan=6| | ||
|- | |- | ||
− | | <nowiki>||</nowiki> | + | | |
+ | | <nowiki>||</nowiki> | ||
|colspan=6| | |colspan=6| | ||
|- | |- | ||
+ | | '''lowest:''' | ||
| ?: | | ?: | ||
|colspan=6| | |colspan=6| | ||
|} | |} | ||
− | The dot | + | The dot ['''.'''] symbol ([[Grammar|"OOP notation"]] for a function call, where <code>a'''.'''function(b)</code> is equivalent to <code>function(a, b)</code>) has a higher precedence than any operator – for example, |
− | + | <div {{BoxWidthIndent|20|2}} > | |
+ | a*b.function(c) | ||
+ | </div> | ||
+ | is equivalent to | ||
+ | <div {{BoxWidthIndent|20|2}} > | ||
+ | a*function(b, c) | ||
+ | </div> | ||
+ | and not | ||
+ | <div {{BoxWidthIndent|20|2}} > | ||
+ | function(a*b, c) | ||
+ | </div> | ||
+ | |||
+ | </div> | ||
+ | |||
+ | |||
---- | ---- | ||
Back to [[AviSynth Syntax]]. | Back to [[AviSynth Syntax]]. |
Revision as of 06:37, 12 March 2016
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.
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)
and not
function(a*b, c)
Back to AviSynth Syntax.