PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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>
10These 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">
11Public 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
17<span class="comment">// Compare equality between two objects of the same type.</span>
18<span class="comment">// Uses the object's opEquals method to perform the comparison, or if that doesn't exist the opCmp method.</span>
19<span class="comment">// Returns a negative value if the comparison couldn't be performed.</span>
20<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);
21
22<span class="comment">// Compile and execute simple statements.</span>
23<span class="comment">// The module is optional. If given the statements can access the entities compiled in the module.</span>
24<span class="comment">// The caller can optionally provide its own context, for example if a context should be reused.</span>
25<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);
26</pre></div><h2><a class="anchor" name="doc_addon_helpers_2">
27Example</a></h2>
28To compare two script objects the application can execute the following code:<p>
29<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)
30{
31  <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>();
32  <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>();
33
34  <span class="keywordtype">int</span> cmp;
35  <span class="keywordtype">int</span> r = CompareRelation(engine, a, b, typeId, cmp);
36  <span class="keywordflow">if</span>( r &lt; 0 )
37  {
38    cout &lt;&lt; <span class="stringliteral">"The relation between a and b cannot be established b"</span> &lt;&lt; endl;
39  }
40  <span class="keywordflow">else</span>
41  {
42    <span class="keywordflow">if</span>( cmp &lt; 0 )
43      cout &lt;&lt; <span class="stringliteral">"a is smaller than b"</span> &lt;&lt; endl;
44    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( cmp == 0 )
45      cout &lt;&lt; <span class="stringliteral">"a is equal to b"</span> &lt;&lt; endl;
46    <span class="keywordflow">else</span>
47      cout &lt;&lt; <span class="stringliteral">"a is greater than b"</span> &lt;&lt; endl;
48  }
49}
50</pre></div> </div>
51<hr size="1"><address style="text-align: right;"><small>Generated on Wed Dec 16 19:34:50 2009 for AngelScript by&nbsp;
52<a href="http://www.doxygen.org/index.html">
53<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
54</body>
55</html>