Angelscript/docs/manual/doc_addon_helpers.html

188 lines
15 KiB
HTML
Raw Permalink Normal View History

2021-04-12 18:25:02 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Helper functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">AngelScript
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('doc_addon_helpers.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Helper functions </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scripthelper/</p>
<p>These helper functions simplify the implementation of common tasks. They can be used as is or can serve as the starting point for your own framework.</p>
<h1><a class="anchor" id="doc_addon_helpers_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="comment">// Compare relation between two objects of the same type.</span></div>
<div class="line"><span class="comment">// Uses the object&#39;s opCmp method to perform the comparison.</span></div>
<div class="line"><span class="comment">// Returns a negative value if the comparison couldn&#39;t be performed.</span></div>
<div class="line"><span class="keywordtype">int</span> CompareRelation(<a class="code" href="classas_i_script_engine.html">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);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Compare equality between two objects of the same type.</span></div>
<div class="line"><span class="comment">// Uses the object&#39;s opEquals method to perform the comparison, or if that doesn&#39;t exist the opCmp method.</span></div>
<div class="line"><span class="comment">// Returns a negative value if the comparison couldn&#39;t be performed.</span></div>
<div class="line"><span class="keywordtype">int</span> CompareEquality(<a class="code" href="classas_i_script_engine.html">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);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Compile and execute simple statements.</span></div>
<div class="line"><span class="comment">// The module is optional. If given the statements can access the entities compiled in the module.</span></div>
<div class="line"><span class="comment">// The caller can optionally provide its own context, for example if a context should be reused.</span></div>
<div class="line"><span class="keywordtype">int</span> ExecuteString(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *code, <a class="code" href="classas_i_script_module.html">asIScriptModule</a> *mod = 0, <a class="code" href="classas_i_script_context.html">asIScriptContext</a> *ctx = 0);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Compile and execute simple statements with option of return value.</span></div>
<div class="line"><span class="comment">// The module is optional. If given the statements can access the entitites compiled in the module.</span></div>
<div class="line"><span class="comment">// The caller can optionally provide its own context, for example if a context should be reused.</span></div>
<div class="line"><span class="keywordtype">int</span> ExecuteString(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *code, <span class="keywordtype">void</span> *ret, <span class="keywordtype">int</span> retTypeId, <a class="code" href="classas_i_script_module.html">asIScriptModule</a> *mod = 0, <a class="code" href="classas_i_script_context.html">asIScriptContext</a> *ctx = 0);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Format the details of the script exception into a human readable text.</span></div>
<div class="line"><span class="comment">// Whenever the asIScriptContext::Execute method returns asEXECUTION_EXCEPTION, the application </span></div>
<div class="line"><span class="comment">// can call this function to get more information about that exception in a human readable form.</span></div>
<div class="line"><span class="comment">// The information obtained includes the current function, the script source section, </span></div>
<div class="line"><span class="comment">// program position in the source section, and the exception description itself.</span></div>
<div class="line">std::string GetExceptionInfo(<a class="code" href="classas_i_script_context.html">asIScriptContext</a> *ctx, <span class="keywordtype">bool</span> showStack = <span class="keyword">false</span>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Write registered application interface to file.</span></div>
<div class="line"><span class="comment">// This function creates a file with the configuration for the offline compiler, asbuild, in the samples.</span></div>
<div class="line"><span class="comment">// If you wish to use the offline compiler you should call this function from you application after the </span></div>
<div class="line"><span class="comment">// application interface has been fully registered. This way you will not have to create the configuration</span></div>
<div class="line"><span class="comment">// file manually.</span></div>
<div class="line"><span class="keywordtype">int</span> WriteConfigToFile(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *filename);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Write the registered application interface to a text stream. </span></div>
<div class="line"><span class="keywordtype">int</span> WriteConfigToStream(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine, std::ostream &amp;strm); </div>
<div class="line"> </div>
<div class="line"><span class="comment">// Loads an interface from a text stream and configures the engine with it. This will not </span></div>
<div class="line"><span class="comment">// set the correct function pointers, so it is not possible to use this engine to execute</span></div>
<div class="line"><span class="comment">// scripts, but it can be used to compile scripts and save the byte code.</span></div>
<div class="line"><span class="keywordtype">int</span> ConfigEngineFromStream(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine, std::istream &amp;strm, <span class="keyword">const</span> <span class="keywordtype">char</span> *nameOfStream = <span class="stringliteral">&quot;config&quot;</span>, <a class="code" href="classas_i_string_factory.html">asIStringFactory</a> *stringFactory = 0);</div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_helpers_2"></a>
Example</h1>
<p>To compare two script objects the application can execute the following code:</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> Compare(<a class="code" href="classas_i_script_object.html">asIScriptObject</a> *a, <a class="code" href="classas_i_script_object.html">asIScriptObject</a> *b)</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine = a-&gt;<a class="code" href="classas_i_script_object.html#a5dda2d380ae1580e15ddf9d95893c57a">GetEngine</a>();</div>
<div class="line"> <span class="keywordtype">int</span> typeId = a-&gt;<a class="code" href="classas_i_script_object.html#a19c5ab9d8adb0f921bf0b6474d97f468">GetTypeId</a>();</div>
<div class="line"> </div>
<div class="line"> <span class="keywordtype">int</span> cmp;</div>
<div class="line"> <span class="keywordtype">int</span> r = CompareRelation(engine, a, b, typeId, cmp);</div>
<div class="line"> <span class="keywordflow">if</span>( r &lt; 0 )</div>
<div class="line"> {</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;The relation between a and b cannot be established b&quot;</span> &lt;&lt; endl;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">if</span>( cmp &lt; 0 )</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;a is smaller than b&quot;</span> &lt;&lt; endl;</div>
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span>( cmp == 0 )</div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;a is equal to b&quot;</span> &lt;&lt; endl;</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> cout &lt;&lt; <span class="stringliteral">&quot;a is greater than b&quot;</span> &lt;&lt; endl;</div>
<div class="line"> }</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div class="ttc" id="aclassas_i_script_context_html"><div class="ttname"><a href="classas_i_script_context.html">asIScriptContext</a></div><div class="ttdoc">The interface to the virtual machine.</div><div class="ttdef"><b>Definition:</b> angelscript.h:2717</div></div>
<div class="ttc" id="aclassas_i_script_object_html_a5dda2d380ae1580e15ddf9d95893c57a"><div class="ttname"><a href="classas_i_script_object.html#a5dda2d380ae1580e15ddf9d95893c57a">asIScriptObject::GetEngine</a></div><div class="ttdeci">virtual asIScriptEngine * GetEngine() const =0</div><div class="ttdoc">Return the script engine.</div></div>
<div class="ttc" id="aclassas_i_string_factory_html"><div class="ttname"><a href="classas_i_string_factory.html">asIStringFactory</a></div><div class="ttdoc">The interface for the string factory.</div><div class="ttdef"><b>Definition:</b> angelscript.h:2150</div></div>
<div class="ttc" id="aclassas_i_script_engine_html"><div class="ttname"><a href="classas_i_script_engine.html">asIScriptEngine</a></div><div class="ttdoc">The engine interface.</div><div class="ttdef"><b>Definition:</b> angelscript.h:1092</div></div>
<div class="ttc" id="aclassas_i_script_module_html"><div class="ttname"><a href="classas_i_script_module.html">asIScriptModule</a></div><div class="ttdoc">The interface to the script modules.</div><div class="ttdef"><b>Definition:</b> angelscript.h:2218</div></div>
<div class="ttc" id="aclassas_i_script_object_html_a19c5ab9d8adb0f921bf0b6474d97f468"><div class="ttname"><a href="classas_i_script_object.html#a19c5ab9d8adb0f921bf0b6474d97f468">asIScriptObject::GetTypeId</a></div><div class="ttdeci">virtual int GetTypeId() const =0</div><div class="ttdoc">Returns the type id of the object.</div></div>
<div class="ttc" id="aclassas_i_script_object_html"><div class="ttname"><a href="classas_i_script_object.html">asIScriptObject</a></div><div class="ttdoc">The interface for an instance of a script object.</div><div class="ttdef"><b>Definition:</b> angelscript.h:3413</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Sat Dec 5 2020 23:20:24 for AngelScript by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.18 </li>
</ul>
</div>
</body>
</html>