Angelscript/docs/manual/doc_as_vs_cpp_types.html

188 lines
12 KiB
HTML

<!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: Datatypes in AngelScript and C++</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_as_vs_cpp_types.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">Datatypes in AngelScript and C++ </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="doc_as_vs_cpp_types_1"></a>
Primitives</h1>
<p>Primitives in AngelScript have direct matches in C++.</p>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100"><b>AngelScript</b></td><td width="150"><b>C++</b></td><td width="100"><b>Size (bits)</b> </td></tr>
<tr>
<td>void </td><td>void </td><td>0 </td></tr>
<tr>
<td>int8 </td><td>signed char </td><td>8 </td></tr>
<tr>
<td>int16 </td><td>signed short </td><td>16 </td></tr>
<tr>
<td>int </td><td>signed int (*) </td><td>32 </td></tr>
<tr>
<td>int64 </td><td>signed int64_t </td><td>64 </td></tr>
<tr>
<td>uint8 </td><td>unsigned char </td><td>8 </td></tr>
<tr>
<td>uint16</td><td>unsigned short </td><td>16 </td></tr>
<tr>
<td>uint </td><td>unsigned int (*) </td><td>32 </td></tr>
<tr>
<td>uint64</td><td>unsigned uint64_t </td><td>64 </td></tr>
<tr>
<td>float </td><td>float </td><td>32 </td></tr>
<tr>
<td>double</td><td>double </td><td>64 </td></tr>
<tr>
<td>bool </td><td>bool </td><td>8 (**) </td></tr>
</table>
<p>(*) An int can actually be of varying size on different platforms in C++, but most commonly it is 32 bits long. AngelScript will always assume 32 bits though.</p>
<p>(**) On 32 bit PowerPC platforms the bool type commonly have the size of 32 bit, when compiled on such platforms AngelScript also uses 32 bits for the bool type</p>
<h1><a class="anchor" id="doc_as_vs_cpp_types_5"></a>
Strings</h1>
<p>AngelScript expects the application to register its own <a class="el" href="doc_strings.html">string type</a>, so the string types should match perfectly.</p>
<p>The char* string type that is so convenient in C++ is however very difficult to use in a scripted environment where you do not have full control over how it is used. For that reason it is recommended that you wrap any functions that use the char* string type so that the string is properly converted to an object that can be safely handled by both the application and the script engine, e.g. std::string or another class of your preference.</p>
<h1><a class="anchor" id="doc_as_vs_cpp_types_2"></a>
Arrays</h1>
<p>AngelScript also expects the application to register the type that should be used for <a class="el" href="doc_arrays.html">dynamic arrays</a>. Normally this is done by registering the <a class="el" href="doc_addon_array.html">array template object</a> add-on, but the application is free to do it differently.</p>
<p>It is also possible to have different object types for different array types, so the application can match the array type exactly with the types used in C++.</p>
<h1><a class="anchor" id="doc_as_vs_cpp_types_3"></a>
Object handles</h1>
<p>The AngelScript object handles are reference counted pointers to objects. This means that for object handles to work, the object must have some way of counting references, for example an AddRef/Release method pair.</p>
<p>When AngelScript passes an object handle by value to a function it increases the reference count to count for the argument instance, thus the function is responsible for releasing the reference once it is finished with it. In the same manner AngelScript expects any handle returned from a function to already have the reference accounted for.</p>
<p>However, when registering functions/methods with AngelScript the application can tell the library that it should automatically take care of releasing the handle references once a function return, likewise for returned handles. This is done by adding a + sign to the @ type modifier. When doing this an object handle can be safely passed to a C++ function that expects a normal pointer, but don't release it afterwards.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="doc_obj_handle.html">Object handles to the application</a></dd></dl>
<h1><a class="anchor" id="doc_as_vc_cpp_types_5"></a>
Script classes and interfaces</h1>
<p>All script classes and interfaces are seen as the <a class="el" href="classas_i_script_object.html">asIScriptObject</a> type by the application. The <a class="el" href="classas_i_script_object.html">asIScriptObject</a> interface has methods to determine the actual type of the script class or interface, as well as to interact with the actual object instance.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="doc_use_script_class.html">Using script classes</a></dd></dl>
<h1><a class="anchor" id="doc_as_vc_cpp_types_6"></a>
Function pointers</h1>
<p>All script function pointers are seen as the <a class="el" href="classas_i_script_function.html">asIScriptFunction</a> type by the application. The <a class="el" href="classas_i_script_function.html">asIScriptFunction</a> type has methods to obtain the name of the function and the parameter and return types, etc.</p>
<h1><a class="anchor" id="doc_as_vs_cpp_types_4"></a>
Parameter references</h1>
<p>Because AngelScript needs to guarantee validity of pointers at all times, it doesn't always pass references to the true object to the function parameter. Instead it creates a copy of the object, whose reference is passed to the function, and if the reference is marked to return a value, the clone is copied back to the original object (if it still exists) once the function returns.</p>
<p>Because of this, AngelScript's parameter references are mostly compatible with C++ references, or pointers, except that the address normally shouldn't be stored for later use, since the object may be destroyed once the function returns.</p>
<p>If it is necessary to store the address of the object, then object handles should be used instead.</p>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" valign="top"><b>Reference</b></td><td valign="top"><b>Description</b> </td></tr>
<tr>
<td valign="top">&amp;in</td><td>A copy of the value is always taken and the reference to the copy is passed to the function. For script functions this is not useful, but it is maintained for compatibility with application registered functions. </td></tr>
<tr>
<td valign="top">const &amp;in</td><td>If the life time of the value can be guaranteed to be valid during the execution of the function, the reference to the true object is passed to the function, otherwise a copy is made. </td></tr>
<tr>
<td valign="top">&amp;out</td><td>A reference to an unitialized value is passed to the function. When the function returns the value is copied to the true reference. The argument expression is evaluated only after the function call. This is the best way to have functions return multiple values. </td></tr>
<tr>
<td valign="top">const &amp;out</td><td>Useless as the function wouldn't be able to modify the value. </td></tr>
<tr>
<td valign="top">&amp;inout</td><td>The true reference is always passed to the function. Only objects that support object handles can be used with this type as they can always be guaranteed to stay alive during the call. </td></tr>
<tr>
<td valign="top">const &amp;inout</td><td>The referred to object will be read-only. </td></tr>
</table>
<p>If the application wants parameter references that work like they do in C++, then this can be allowed by <a class="el" href="doc_adv_custom_options.html#doc_adv_custom_options_lang_mod">setting an engine property</a>. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- 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>