/xbmc/visualizations/Vortex/angelscript/docs/manual/doc_expressions.html

http://github.com/xbmc/xbmc · HTML · 201 lines · 200 code · 0 blank · 1 comment · 0 complexity · 443dde34deee72f6a897a037ed5be151 MD5 · raw file

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  3. <title>AngelScript: Expressions</title>
  4. <link href="tabs.css" rel="stylesheet" type="text/css">
  5. <link href="doxygen.css" rel="stylesheet" type="text/css">
  6. </head><body>
  7. <!-- Generated by Doxygen 1.5.9 -->
  8. <div class="contents">
  9. <h1><a class="anchor" name="doc_expressions">Expressions </a></h1><ul>
  10. <li><a class="el" href="doc_expressions.html#assignment">Assignments</a></li><li><a class="el" href="doc_expressions.html#compound">Compound assignments</a></li><li><a class="el" href="doc_expressions.html#function">Function call</a></li><li><a class="el" href="doc_expressions.html#conversion">Type conversions</a></li><li><a class="el" href="doc_expressions.html#math">Math operators</a></li><li><a class="el" href="doc_expressions.html#bits">Bitwise operators</a></li><li><a class="el" href="doc_expressions.html#logic">Logic operators</a></li><li><a class="el" href="doc_expressions.html#equal">Equality comparison operators</a></li><li><a class="el" href="doc_expressions.html#relation">Relational comparison operators</a></li><li><a class="el" href="doc_expressions.html#identity">Identity comparison operators</a></li><li><a class="el" href="doc_expressions.html#increment">Increment operators</a></li><li><a class="el" href="doc_expressions.html#index">Indexing operator</a></li><li><a class="el" href="doc_expressions.html#condition">Conditional expression</a></li><li><a class="el" href="doc_expressions.html#member">Member access</a></li><li><a class="el" href="doc_expressions.html#handle">Handle-of</a></li><li><a class="el" href="doc_expressions.html#parenthesis">Parenthesis</a></li><li><a class="el" href="doc_expressions.html#scope">Scope resolution</a></li></ul>
  11. <h2><a class="anchor" name="assignment">
  12. Assignments</a></h2>
  13. <pre> lvalue = rvalue;</pre><p>
  14. <code>lvalue</code> 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.<h2><a class="anchor" name="compound">
  15. Compound assignments</a></h2>
  16. <pre>
  17. lvalue += rvalue;
  18. lvalue = lvalue + rvalue;
  19. </pre><p>
  20. A compound assignment is a combination of an operator followed by the assignment. The two expressions above means practically the same thing. Except that first one is more efficient in that the lvalue is only evaluated once, which can make a difference if the lvalue is complex expression in itself.<p>
  21. Available operators: <code>+= -= *= /= = &amp;= |= ^= &lt;&lt;= &gt;&gt;= &gt;&gt;&gt;=</code><h2><a class="anchor" name="function">
  22. Function call</a></h2>
  23. <pre>
  24. func();
  25. func(arg);
  26. func(arg1, arg2);
  27. lvalue = func();
  28. </pre><p>
  29. Functions are called to perform an action, and possibly return a value that can be used in further operations. If a function takes more than one argument, the argument expressions are evaluated in the reverse order, i.e. the last argument is evaluated first.<h2><a class="anchor" name="conversion">
  30. Type conversions</a></h2>
  31. <pre>
  32. // implicitly convert the clss handle to a intf handle
  33. intf @a = @clss();</pre><p>
  34. <pre> // explicitly convert the intf handle to a clss handle
  35. clss @b = cast&lt;clss&gt;(a);
  36. </pre><p>
  37. 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.<p>
  38. The above is called a reference cast, and only works for types that support object handles. In this case the handle still refers to the same object, it is just exposed through a different interface.<p>
  39. Types that do not support object handles can be converted with a value cast instead. In this case a new value is constructed, or in case of objects a new instance of the object is created.<p>
  40. <pre>
  41. // implicit value cast
  42. int a = 1.0f;</pre><p>
  43. <pre> // explicit value cast
  44. float b = float(a)/2;
  45. </pre><p>
  46. 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.<h2><a class="anchor" name="math">
  47. Math operators</a></h2>
  48. <pre>
  49. c = -(a + b);
  50. </pre><p>
  51. <table cellspacing="0" cellpadding="0" border="0">
  52. <tr>
  53. <td width="70" valign="top"><b>operator</b></td><td width="100" valign="top"><b>description</b></td><td width="80" valign="top"><b>left hand</b></td><td width="80" valign="top"><b>right hand</b></td><td width="80" valign="top"><b>result</b> </td></tr>
  54. <tr>
  55. <td width="70" valign="top"><code>+</code> </td><td width="100" valign="top">unary positive </td><td width="80" valign="top">&nbsp; </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td></tr>
  56. <tr>
  57. <td width="70" valign="top"><code>-</code> </td><td width="100" valign="top">unary negative </td><td width="80" valign="top">&nbsp; </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td></tr>
  58. <tr>
  59. <td width="70" valign="top"><code>+</code> </td><td width="100" valign="top">addition </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td></tr>
  60. <tr>
  61. <td width="70" valign="top"><code>-</code> </td><td width="100" valign="top">subtraction </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td></tr>
  62. <tr>
  63. <td width="70" valign="top"><code>*</code> </td><td width="100" valign="top">multiplication </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td></tr>
  64. <tr>
  65. <td width="70" valign="top"><code>/</code> </td><td width="100" valign="top">division </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td></tr>
  66. <tr>
  67. <td width="70" valign="top"><code>%</code> </td><td width="100" valign="top">modulos </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td><td width="80" valign="top"><em>NUM</em> </td></tr>
  68. </table>
  69. <p>
  70. Plus and minus can be used as unary operators as well. NUM can be exchanged for any numeric type, e.g. <code>int</code> or <code>float</code>. 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 <code>uint</code>.<h2><a class="anchor" name="bits">
  71. Bitwise operators</a></h2>
  72. <pre>
  73. c = ~(a | b);
  74. </pre><p>
  75. <table cellspacing="0" cellpadding="0" border="0">
  76. <tr>
  77. <td width="70" valign="top"><b>operator</b> </td><td width="130" valign="top"><b>description</b> </td><td width="80" valign="top"><b>left hand</b> </td><td width="80" valign="top"><b>right hand</b> </td><td width="80" valign="top"><b>result</b> </td></tr>
  78. <tr>
  79. <td width="70" valign="top"><code>~</code> </td><td width="130" valign="top">bitwise complement </td><td width="80" valign="top">&nbsp; </td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em> </td></tr>
  80. <tr>
  81. <td width="70" valign="top"><code>&amp;</code> </td><td width="130" valign="top">bitwise and </td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em> </td></tr>
  82. <tr>
  83. <td width="70" valign="top"><code>|</code> </td><td width="130" valign="top">bitwise or </td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em> </td></tr>
  84. <tr>
  85. <td width="70" valign="top"><code>^</code> </td><td width="130" valign="top">bitwise xor </td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em> </td></tr>
  86. <tr>
  87. <td width="70" valign="top"><code>&lt;&lt;</code> </td><td width="130" valign="top">left shift </td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em> </td></tr>
  88. <tr>
  89. <td width="70" valign="top"><code>&gt;&gt;</code> </td><td width="130" valign="top">right shift </td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em> </td></tr>
  90. <tr>
  91. <td width="70" valign="top"><code>&gt;&gt;&gt;</code></td><td width="130" valign="top">arithmetic right shift</td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em></td><td width="80" valign="top"><em>NUM</em> </td></tr>
  92. </table>
  93. <p>
  94. All except <code>~</code> are dual operators.<h2><a class="anchor" name="logic">
  95. Logic operators</a></h2>
  96. <pre>
  97. if( a and b or not c )
  98. {
  99. // ... do something
  100. }
  101. </pre><p>
  102. <table cellspacing="0" cellpadding="0" border="0">
  103. <tr>
  104. <td width="70" valign="top"><b>operator</b> </td><td width="130" valign="top"><b>description</b> </td><td width="80" valign="top"><b>left hand</b> </td><td width="80" valign="top"><b>right hand</b> </td><td width="80" valign="top"><b>result</b> </td></tr>
  105. <tr>
  106. <td width="70" valign="top"><code>not</code></td><td width="130" valign="top">logical not </td><td width="80" valign="top">&nbsp; </td><td width="80" valign="top"><code>bool</code></td><td width="80" valign="top"><code>bool</code> </td></tr>
  107. <tr>
  108. <td width="70" valign="top"><code>and</code></td><td width="130" valign="top">logical and </td><td width="80" valign="top"><code>bool</code></td><td width="80" valign="top"><code>bool</code></td><td width="80" valign="top"><code>bool</code> </td></tr>
  109. <tr>
  110. <td width="70" valign="top"><code>or</code> </td><td width="130" valign="top">logical or </td><td width="80" valign="top"><code>bool</code></td><td width="80" valign="top"><code>bool</code></td><td width="80" valign="top"><code>bool</code> </td></tr>
  111. <tr>
  112. <td width="70" valign="top"><code>xor</code></td><td width="130" valign="top">logical exclusive or</td><td width="80" valign="top"><code>bool</code></td><td width="80" valign="top"><code>bool</code></td><td width="80" valign="top"><code>bool</code> </td></tr>
  113. </table>
  114. <p>
  115. Boolean operators only evaluate necessary terms. For example in expression <code>a and b</code>, <code>b</code> is only evaluated if <code>a</code> is <code>true</code>.<p>
  116. Each of the logic operators can be written as symbols as well, i.e. <code>||</code> for <code>or</code>, <code>&amp;&amp;</code> for <code>and</code>, <code>^^</code> for <code>xor</code>, and <code>!</code> for <code>not</code>.<h2><a class="anchor" name="equal">
  117. Equality comparison operators</a></h2>
  118. <pre>
  119. if( a == b )
  120. {
  121. // ... do something
  122. }
  123. </pre><p>
  124. The operators <code>==</code> and <code>!=</code> are used to compare two values to determine if they are equal or not equal, respectively. The result of this operation is always a boolean value.<h2><a class="anchor" name="relation">
  125. Relational comparison operators</a></h2>
  126. <pre>
  127. if( a &gt; b )
  128. {
  129. // ... do something
  130. }
  131. </pre><p>
  132. The operators <code>&lt;</code>, <code>&gt;</code>, <code>&lt;=</code>, and <code>&gt;=</code> are used to compare two values to determine their relationship. The result is always a boolean value.<h2><a class="anchor" name="identity">
  133. Identity comparison operators</a></h2>
  134. <pre>
  135. if( a is null )
  136. {
  137. // ... do something
  138. }
  139. else if( a is b )
  140. {
  141. // ... do something
  142. }
  143. </pre><p>
  144. The operators <code>is</code> and <code>!is</code> are used to compare the identity of two objects, i.e. to determine if the two are the same object or not. These operators are only valid for reference types as they compare the address of two objects. The result is always a boolean value.<h2><a class="anchor" name="increment">
  145. Increment operators</a></h2>
  146. <pre>
  147. // The following means a = i; i = i + 1;
  148. a = i++;</pre><p>
  149. <pre> // The following means i = i - 1; b = i;
  150. b = --i;
  151. </pre><p>
  152. These operators can be placed either before or after an lvalue to increment/decrement its value either before or after the value is used in the expression. The value is always incremented or decremented with 1.<h2><a class="anchor" name="index">
  153. Indexing operator</a></h2>
  154. <pre>
  155. arr[i] = 1;
  156. </pre><p>
  157. This operator is used to access an element contained within the object. Depending on the object type, the expression between the <code>[]</code> needs to be of different types.<h2><a class="anchor" name="condition">
  158. Conditional expression</a></h2>
  159. <pre>
  160. choose ? a : b;
  161. </pre><p>
  162. If the value of <code>choose</code> is <code>true</code> then the expression returns <code>a</code> otherwise it will return <code>b</code>. Both <code>a</code> and <code>b</code> must be of the same type.<h2><a class="anchor" name="member">
  163. Member access</a></h2>
  164. <pre>
  165. object.property = 1;
  166. object.method();
  167. </pre><p>
  168. <code>object</code> must be an expression resulting in a data type that have members. <code>property</code> is the name of a member variable that can be read/set directly. <code>method</code> is the name of a member method that can be called on the object.<h2><a class="anchor" name="handle">
  169. Handle-of</a></h2>
  170. <pre>
  171. // Make handle reference the object instance
  172. @handle = @object;</pre><p>
  173. <pre> // Clear the handle and release the object it references
  174. @handle = null;
  175. </pre><p>
  176. Object handles are references to an object. More than one handle can reference the same object, and only when no more handles reference an object is the object destroyed.<p>
  177. The members of the object that the handle references are accessed the same way through the handle as if accessed directly through the object variable, i.e. with <code>.</code> operator.<h2><a class="anchor" name="parenthesis">
  178. Parenthesis</a></h2>
  179. <pre>
  180. a = c * (a + b);
  181. if( (a or b) and c )
  182. {
  183. // ... do something
  184. }
  185. </pre><p>
  186. Parenthesis are used to group expressions when the <a class="el" href="doc_operator_precedence.html">operator precedence</a> does not give the desired order of evaluation.<h2><a class="anchor" name="scope">
  187. Scope resolution</a></h2>
  188. <pre>
  189. int value;
  190. void function()
  191. {
  192. int value; // local variable overloads the global variable
  193. ::value = value; // use scope resolution operator to refer to the global variable
  194. }
  195. </pre><p>
  196. The scope resolution operator <code>::</code> can be used to access variables or functions from another scope when the name is overloaded by a local variable or function. Write the scope name on the left (or blank for the global scope) and the name of the variable/function on the right. </div>
  197. <hr size="1"><address style="text-align: right;"><small>Generated on Wed Dec 16 19:34:51 2009 for AngelScript by&nbsp;
  198. <a href="http://www.doxygen.org/index.html">
  199. <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
  200. </body>
  201. </html>