Eyeon:Script/Reference/Language/Operators

From VFXPedia

< Eyeon:Script | Reference | Language
Revision as of 16:41, 3 January 2007 by Peter (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Arithmetic Operators

eyeonScript supports the usual arithmetic operators:

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • ^ (exponentiation i.e. x^y)
  • - (negation i.e. -x)

If the operands are numbers, or strings that can be converted to numbers ( see tonumber ), then all operations usual meaning.

Concatenation

The string concatenation operator in Lua is denoted by two dots (..). If one or both operands are numbers, then eyeonScript will attempt the operands to strings. This will only succeed for numeric values.

  • "Hello " .. "World"
  • "Test " .. 1

Logical Operators

The logical operators in eyeonScript are:

  • and
  • or
  • not

Like the control statements, all logical operators consider both "false" and "nil" as "false" and anything else as "true".

The operator "not" always returns "false" or "true".

The conjunction operator "and" returns its first operand if its value is "false" or "nil"; otherwise, "and" returns its second operand. The disjunction operator "or" returns its first operand if it is different from "nil" and "false"; otherwise, "or" returns its second operand. Both "and" and "or" use short-cut evaluation, that is, the second operand is evaluated only if necessary. For example,

  • 10 or error() -> 10
  • nil or "a" -> "a"
  • nil and 10 -> nil
  • false and error() -> false
  • false and nil -> false
  • false or nil -> nil
  • 10 and 20 -> 20


Operator Precedence

Operator precedence in eyeonScript follows the list below, from lower to higher priority:

  • or
  • and
  • < > <= >= ~= ==
  • ..
  • + -
  • * /  %
  • not # - (unary)
  • ^

As usual, you can use parentheses to change the precedences of an expression. The concatenation ('..') and exponentiation ('^') operators are right associative. All other binary operators are left associative.

Relational Operators

The relational operators in eyeonScript are

  • == (equal to)
  • ~= (not equal to)
  • < (less than)
  • > (greater than)
  • <=(less than or equal to)
  • >= (greater than or equal to)

These operators always result in true or false results.

Equality (==) first compares the type of its operands. If the types are different, then the result is false. Otherwise, the values of the operands are compared. Numbers and strings are compared in the usual way. Tables, userdata, and functions are compared by reference, that is, two tables are considered equal only if they are the same table.

Every time you create a new table (or userdata, or function), this new value is different from any previously existing value.

NOTE: The terms are not converted before equality comparisons. Thus, "0"==0 evaluates to false, and t[0] and t["0"] denote different entries in a table.

The operator ~= is exactly the negation of equality (==).

The order operators work as follows. If both operands are numbers, then they are compared as such. Otherwise, if both operands are strings, then their values are compared according to the current locale.


Tips for Operators (edit)

EyeonTips:Script/Reference/Language/Operators