Expressions

Todo:
Clean up this page

Assignments

LVALUE = EXPR

LVALUE must be an expression that evaluates to a memory location where the expression value can be stored, e.g. a variable. An assignment evaluates to the same value and type of the data stored. The right hand expression is always computed before the left.

Compound assignments

LVALUE OP EXPR

In this case the expression is combined with the LVALUE using on of the available operators: += -= *= /= = &= |= ^= <<= >>= >>>=

Function call

FUNCTION(ARGS)

Functions can only be called in expressions. Functions with no return value (void) can only be called when no data is expected, e.g. alone on a line.

Type conversions

intf @a = clss();

convert the intf handle to a clss handle
clss @b = cast<clss>(a);

Object handles can be converted to other object handles with the cast operator. If the cast is valid, i.e. the true object implements the class or interface being requested, the operator returns a valid handle. If the cast is not valid, the cast returns a null handle.

Primitive types can also be converted using the cast operator, but there is also an alternative syntax.

int   a = 1;
float b = float(a)/2;

In most cases an explicit cast is not necessary for primitive types, however, as the compiler is usually able to do an implicit cast to the correct type.

The compiler is also able to use declared object constructors when performing implicit conversions. For example, if you have an object type that can be constructed with an integer parameter, you will be able to pass integer expressions to functions that expect that object type, as the compiler will automatically construct the object for you. Note, however that this conversion cannot be done implicitly if the function expects a reference argument.

Math operators

operatordescriptionleft handright handresult
+ unary positive   NUM NUM
- unary negative   NUM NUM
+ addition NUM NUM NUM
- subtraction NUM NUM NUM
* multiplication NUM NUM NUM
/ division NUM NUM NUM
% modulos NUM NUM NUM

Plus and minus can be used as unary operators as well. NUM can be exchanged for any numeric type, e.g. int or float. Both terms of the dual operations will be implicitly converted to have the same type. The result is always the same type as the original terms. One exception is unary negative which is not available for uint.

Bitwise operators

operator description left hand right hand result
~ bitwise complement   NUMNUM
& bitwise and NUMNUMNUM
| bitwise or NUMNUMNUM
^ bitwise xor NUMNUMNUM
<< left shift NUMNUMNUM
>> right shift NUMNUMNUM
>>>arithmetic right shiftNUMNUMNUM

All except ~ are dual operators.

Logic operators

operator description left hand right hand result
notlogical not   boolbool
andlogical and boolboolbool
or logical or boolboolbool
xorlogical exclusive orboolboolbool

Boolean operators only evaluate necessary terms. For example in expression a and b, b is only evaluated if a is true.

Comparison operators

operator descriptionleft handright handresult
== equal value value bool
!= not equal value value bool
< less than value value bool
> greater than value value bool
<=less or equal value value bool
>=greater or equal value value bool

Increment operators

++ --

These operators can be placed either before or after an lvalue to increment (or decrement) its value either before or after the value is used in the expression. The value is always incremented or decremented with 1.

Indexing operator

[EXPR]

This operator can only be used if the application has supports it.

Conditional expression

EXPR ? A : B

If expression is true A is executed, if not then B is executed instead.

Member access

OBJ . MEMBER

OBJ must be an expression resulting in a data type that have members. MEMBER is the name of the member to be accessed. This member may or may not be read only.

Handle-of

@ VAR

VAR is an object that allows its handle to be taken. The handle can then be assigned to a handle variable of the same type, or compared against another handle, or null.


Generated on Sun Aug 17 17:11:13 2008 for AngelScript by  doxygen 1.5.6