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

http://github.com/xbmc/xbmc · HTML · 55 lines · 51 code · 3 blank · 1 comment · 0 complexity · dd983fe71bf4d12f9f9cfa98c306d370 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: Helper functions</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_addon_helpers">Helper functions </a></h1><b>Path:</b> /sdk/add_on/scripthelper/<p>
  10. These helper functions simplify the implemention of common tasks. They can be used as is or can serve as the starting point for your own framework.<h2><a class="anchor" name="doc_addon_helpers_1">
  11. Public C++ interface</a></h2>
  12. <div class="fragment"><pre class="fragment"><span class="comment">// Compare relation between two objects of the same type.</span>
  13. <span class="comment">// Uses the object's opCmp method to perform the comparison.</span>
  14. <span class="comment">// Returns a negative value if the comparison couldn't be performed.</span>
  15. <span class="keywordtype">int</span> CompareRelation(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keywordtype">void</span> *leftObj, <span class="keywordtype">void</span> *rightObj, <span class="keywordtype">int</span> typeId, <span class="keywordtype">int</span> &amp;result);
  16. <span class="comment">// Compare equality between two objects of the same type.</span>
  17. <span class="comment">// Uses the object's opEquals method to perform the comparison, or if that doesn't exist the opCmp method.</span>
  18. <span class="comment">// Returns a negative value if the comparison couldn't be performed.</span>
  19. <span class="keywordtype">int</span> CompareEquality(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keywordtype">void</span> *leftObj, <span class="keywordtype">void</span> *rightObj, <span class="keywordtype">int</span> typeId, <span class="keywordtype">bool</span> &amp;result);
  20. <span class="comment">// Compile and execute simple statements.</span>
  21. <span class="comment">// The module is optional. If given the statements can access the entities compiled in the module.</span>
  22. <span class="comment">// The caller can optionally provide its own context, for example if a context should be reused.</span>
  23. <span class="keywordtype">int</span> ExecuteString(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *code, <a class="code" href="classas_i_script_module.html" title="The interface to the script modules.">asIScriptModule</a> *mod = 0, <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx = 0);
  24. </pre></div><h2><a class="anchor" name="doc_addon_helpers_2">
  25. Example</a></h2>
  26. To compare two script objects the application can execute the following code:<p>
  27. <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> Compare(<a class="code" href="classas_i_script_object.html" title="The interface for an instance of a script object.">asIScriptObject</a> *a, <a class="code" href="classas_i_script_object.html" title="The interface for an instance of a script object.">asIScriptObject</a> *b)
  28. {
  29. <a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine = a-&gt;<a class="code" href="classas_i_script_object.html#5dda2d380ae1580e15ddf9d95893c57a" title="Return the script engine.">GetEngine</a>();
  30. <span class="keywordtype">int</span> typeId = a-&gt;<a class="code" href="classas_i_script_object.html#19c5ab9d8adb0f921bf0b6474d97f468" title="Returns the type id of the object.">GetTypeId</a>();
  31. <span class="keywordtype">int</span> cmp;
  32. <span class="keywordtype">int</span> r = CompareRelation(engine, a, b, typeId, cmp);
  33. <span class="keywordflow">if</span>( r &lt; 0 )
  34. {
  35. cout &lt;&lt; <span class="stringliteral">"The relation between a and b cannot be established b"</span> &lt;&lt; endl;
  36. }
  37. <span class="keywordflow">else</span>
  38. {
  39. <span class="keywordflow">if</span>( cmp &lt; 0 )
  40. cout &lt;&lt; <span class="stringliteral">"a is smaller than b"</span> &lt;&lt; endl;
  41. <span class="keywordflow">else</span> <span class="keywordflow">if</span>( cmp == 0 )
  42. cout &lt;&lt; <span class="stringliteral">"a is equal to b"</span> &lt;&lt; endl;
  43. <span class="keywordflow">else</span>
  44. cout &lt;&lt; <span class="stringliteral">"a is greater than b"</span> &lt;&lt; endl;
  45. }
  46. }
  47. </pre></div> </div>
  48. <hr size="1"><address style="text-align: right;"><small>Generated on Wed Dec 16 19:34:50 2009 for AngelScript by&nbsp;
  49. <a href="http://www.doxygen.org/index.html">
  50. <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
  51. </body>
  52. </html>