console_autodoc.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=11"/>
  6. <meta name="generator" content="Doxygen 1.9.8"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>Torque2D Reference: Console Auto-Documentation</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="search/searchdata.js"></script>
  14. <script type="text/javascript" src="search/search.js"></script>
  15. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  16. <link href="t2d-stylesheet-extra.css" rel="stylesheet" type="text/css"/>
  17. </head>
  18. <body>
  19. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  20. <div id="titlearea">
  21. <table cellspacing="0" cellpadding="0">
  22. <tbody>
  23. <tr id="projectrow">
  24. <td id="projectalign">
  25. <div id="projectname">Torque2D Reference
  26. </div>
  27. </td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- end header part -->
  33. <!-- Generated by Doxygen 1.9.8 -->
  34. <script type="text/javascript">
  35. /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  36. var searchBox = new SearchBox("searchBox", "search/",'.html');
  37. /* @license-end */
  38. </script>
  39. <script type="text/javascript" src="menudata.js"></script>
  40. <script type="text/javascript" src="menu.js"></script>
  41. <script type="text/javascript">
  42. /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  43. $(function() {
  44. initMenu('',true,false,'search.php','Search');
  45. $(document).ready(function() { init_search(); });
  46. });
  47. /* @license-end */
  48. </script>
  49. <div id="main-nav"></div>
  50. <!-- window showing the filter options -->
  51. <div id="MSearchSelectWindow"
  52. onmouseover="return searchBox.OnSearchSelectShow()"
  53. onmouseout="return searchBox.OnSearchSelectHide()"
  54. onkeydown="return searchBox.OnSearchSelectKey(event)">
  55. </div>
  56. <!-- iframe showing the search results (closed by default) -->
  57. <div id="MSearchResultsWindow">
  58. <div id="MSearchResults">
  59. <div class="SRPage">
  60. <div id="SRIndex">
  61. <div id="SRResults"></div>
  62. <div class="SRStatus" id="Loading">Loading...</div>
  63. <div class="SRStatus" id="Searching">Searching...</div>
  64. <div class="SRStatus" id="NoMatches">No Matches</div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </div><!-- top -->
  70. <div><div class="header">
  71. <div class="headertitle"><div class="title">Console Auto-Documentation</div></div>
  72. </div><!--header-->
  73. <div class="contents">
  74. <div class="textblock"><dl class="section see"><dt>See also</dt><dd>consoleDoc.cc</dd></dl>
  75. <h1><a class="anchor" id="console_autodoc_using"></a>
  76. Using Console Auto-Documentation</h1>
  77. <p>There are on the order of three hundred functions exposed to the script language through the console. It is therefore extremely important that they be documented, but due to their number, it is difficult to maintain a seperate reference document.</p>
  78. <p>Therefore, a simple documentation system has been built into the scripting engine. It was initially added by Mark Frohnmayer, and later enhanced by Ben Garney. The scripting engine supports grouping functions and methods, to help organize the several hundred functions, as well as associating a "usage string" with functions and groups.</p>
  79. <dl class="section note"><dt>Note</dt><dd>The results of a console doc dump will vary depending on when you run it. If you run it, for example, while in the game menu, it won't output any data for the script-defined classes which are defined for gameplay. To get comprehensive documentation, you may need to write a special script that will get all your classes loaded into the scripting engine.</dd></dl>
  80. <p>The console documentation system is designed to output a dump of the current state of the scripting engine in a format understandable by Doxygen. It does this by traversing the namespace/class hierarchy in memory at the time of the dump, and outputting psuedo-C++ code equivalent to this class hierarchy.</p>
  81. <h2><a class="anchor" id="console_autodoc_using_script"></a>
  82. For the Scripter...</h2>
  83. <p>Currently, there is no way to associate usage strings or other documentation with script code like you can with C++ code.</p>
  84. <p>You can get a list of all the methods and fields of an object from any object which inherits from <a class="el" href="class_sim_object.html">SimObject</a> (ie, every object), as well as the documentation on those objects by using the dump() method from the console:</p>
  85. <div class="fragment"><div class="line">==&gt;$foo = <span class="keyword">new</span> <a class="code hl_class" href="class_sim_object.html">SimObject</a>();</div>
  86. <div class="line">==&gt;$foo.dump();</div>
  87. <div class="line">Member Fields:</div>
  88. <div class="line">Tagged Fields:</div>
  89. <div class="line">Methods:</div>
  90. <div class="line"> <span class="keyword">delete</span>() - obj.delete()</div>
  91. <div class="line"> dump() - obj.<a class="code hl_function" href="class_sim_object.html#accd2600060dbaee3a3b41aed4034c63c">dump</a>()</div>
  92. <div class="line"> getClassName() - obj.<a class="code hl_function" href="class_console_object.html#a45b489f436c9d32a63f9c3d62f66c892">getClassName</a>()</div>
  93. <div class="line"> getGroup() - obj.<a class="code hl_function" href="class_sim_object.html#a8cd893920348a8bb5566e86b188bba37">getGroup</a>()</div>
  94. <div class="line"> getId() - obj.<a class="code hl_function" href="class_sim_object.html#aa4a7bd634ae9f58bccb125fe45d86fc9">getId</a>()</div>
  95. <div class="line"> getName() - obj.<a class="code hl_function" href="class_sim_object.html#afef631e435982063322597320f4c817f">getName</a>()</div>
  96. <div class="line"> getType() - obj.<a class="code hl_function" href="class_sim_object.html#a604dfe76701f827f0d0787f1ec29b690">getType</a>()</div>
  97. <div class="line"> save() - obj.<a class="code hl_function" href="class_sim_object.html#a86f7c64cb6f7eba36f8a6e391e29492f">save</a>(fileName, &lt;selectedOnly&gt;)</div>
  98. <div class="line"> schedule() - <span class="keywordtype">object</span>.schedule(time, command, &lt;arg1...argN&gt;);</div>
  99. <div class="line"> setName() - obj.setName(newName)</div>
  100. <div class="ttc" id="aclass_console_object_html_a45b489f436c9d32a63f9c3d62f66c892"><div class="ttname"><a href="class_console_object.html#a45b489f436c9d32a63f9c3d62f66c892">ConsoleObject::getClassName</a></div><div class="ttdeci">const char * getClassName() const</div><div class="ttdef"><b>Definition</b> consoleObject.h:756</div></div>
  101. <div class="ttc" id="aclass_sim_object_html"><div class="ttname"><a href="class_sim_object.html">SimObject</a></div><div class="ttdef"><b>Definition</b> simObject.h:234</div></div>
  102. <div class="ttc" id="aclass_sim_object_html_a604dfe76701f827f0d0787f1ec29b690"><div class="ttname"><a href="class_sim_object.html#a604dfe76701f827f0d0787f1ec29b690">SimObject::getType</a></div><div class="ttdeci">U32 getType() const</div><div class="ttdef"><b>Definition</b> simObject.h:623</div></div>
  103. <div class="ttc" id="aclass_sim_object_html_a86f7c64cb6f7eba36f8a6e391e29492f"><div class="ttname"><a href="class_sim_object.html#a86f7c64cb6f7eba36f8a6e391e29492f">SimObject::save</a></div><div class="ttdeci">virtual bool save(const char *pcFilePath, bool bOnlySelected=false)</div><div class="ttdoc">Save object as a TorqueScript File.</div><div class="ttdef"><b>Definition</b> simObject.cc:417</div></div>
  104. <div class="ttc" id="aclass_sim_object_html_a8cd893920348a8bb5566e86b188bba37"><div class="ttname"><a href="class_sim_object.html#a8cd893920348a8bb5566e86b188bba37">SimObject::getGroup</a></div><div class="ttdeci">SimGroup * getGroup() const</div><div class="ttdef"><b>Definition</b> simObject.h:628</div></div>
  105. <div class="ttc" id="aclass_sim_object_html_aa4a7bd634ae9f58bccb125fe45d86fc9"><div class="ttname"><a href="class_sim_object.html#aa4a7bd634ae9f58bccb125fe45d86fc9">SimObject::getId</a></div><div class="ttdeci">SimObjectId getId(void) const</div><div class="ttdef"><b>Definition</b> simObject.h:621</div></div>
  106. <div class="ttc" id="aclass_sim_object_html_accd2600060dbaee3a3b41aed4034c63c"><div class="ttname"><a href="class_sim_object.html#accd2600060dbaee3a3b41aed4034c63c">SimObject::dump</a></div><div class="ttdeci">virtual void dump()</div><div class="ttdef"><b>Definition</b> simObject.cc:1504</div></div>
  107. <div class="ttc" id="aclass_sim_object_html_afef631e435982063322597320f4c817f"><div class="ttname"><a href="class_sim_object.html#afef631e435982063322597320f4c817f">SimObject::getName</a></div><div class="ttdeci">const StringTableEntry getName(void) const</div><div class="ttdef"><b>Definition</b> simObject.h:624</div></div>
  108. </div><!-- fragment --><p>In the <a class="el" href="namespace_torque.html">Torque</a> example app, there are two functions defined in common\client\scriptDoc.cs which automate the process of dumping the documentation. They make use of the <a class="el" href="class_console_logger.html">ConsoleLogger</a> object to output the documentation to a file, and look like this:</p>
  109. <dl class="section note"><dt>Note</dt><dd>You may want to add this code, or code like it, to your project if you have rewritten the script code in common.</dd></dl>
  110. <div class="fragment"><div class="line"><span class="comment">// Writes out all script functions to a file</span></div>
  111. <div class="line">function writeOutFunctions() {</div>
  112. <div class="line"> <span class="keyword">new</span> <a class="code hl_class" href="class_console_logger.html">ConsoleLogger</a>( logger, <span class="stringliteral">&quot;scriptFunctions.txt&quot;</span>, <span class="keyword">false</span> );</div>
  113. <div class="line"> dumpConsoleFunctions();</div>
  114. <div class="line"> logger.delete();</div>
  115. <div class="line">}</div>
  116. <div class="line"> </div>
  117. <div class="line"><span class="comment">// Writes out all script classes to a file</span></div>
  118. <div class="line">function writeOutClasses() {</div>
  119. <div class="line"> <span class="keyword">new</span> <a class="code hl_class" href="class_console_logger.html">ConsoleLogger</a>( logger, <span class="stringliteral">&quot;scriptClasses.txt&quot;</span>, <span class="keyword">false</span> );</div>
  120. <div class="line"> dumpConsoleClasses();</div>
  121. <div class="line"> logger.delete();</div>
  122. <div class="line">}</div>
  123. <div class="ttc" id="aclass_console_logger_html"><div class="ttname"><a href="class_console_logger.html">ConsoleLogger</a></div><div class="ttdef"><b>Definition</b> consoleLogger.h:33</div></div>
  124. </div><!-- fragment --><h2><a class="anchor" id="console_autodoc_using_coder"></a>
  125. For the C++ Coder...</h2>
  126. <dl class="section note"><dt>Note</dt><dd><b>It is of the utmost important that you keep your usage strings up to date!</b> Usage strings are the only way that a scripter has to know how to use the methods, functions, and variables you expose. Misleading, missing, or out of date documentation will make their lives much harder - and yours, too, because you'll have to keep explaining things to them! So make everyone's lives easier - keep your usage strings clear, concise, and up to date.</dd></dl>
  127. <p>There are four types of items which can be documented using the autodocumentation system:</p><ul>
  128. <li><b>Fields</b>, which are defined using the addField() calls. They are documented by passing a string to the usage parameter.</li>
  129. <li><b>Field groups</b>, which are defined using the beginGroup() and endGroup() calls. They are documented by passing a descriptive string to the usage parameter.</li>
  130. <li><b>Method groups</b>, which are defined using beginCommandGroup(), endCommandGroup(), ConsoleMethodGroupEnd(), ConsoleMethodGroupBegin(), ConsoleFunctionGroupEnd(), and ConsoleFunctionGroupBegin().</li>
  131. <li><b>Methods and functions</b>, which are defined using either SimObject::addCommand(), the ConsoleMethod() macro, or the ConsoleFunction() macro. Methods and functions are special in that the usage strings should be in a specific format, so that parameter information can be extracted from them and placed into the Doxygen output.</li>
  132. </ul>
  133. <p>You can use standard Doxygen commands in your comments, to make the documentation clearer. Of particular use are @returns, @param, @note, and @deprecated.</p>
  134. <p><b>Examples using global definitions.</b></p>
  135. <div class="fragment"><div class="line"><span class="comment">// Example of using Doxygen commands.</span></div>
  136. <div class="line">ConsoleFunction(alxGetWaveLen, S32, 2, 2, <span class="stringliteral">&quot;(string filename)&quot;</span></div>
  137. <div class="line"> <span class="stringliteral">&quot;Get length of a wave file\n\n&quot;</span></div>
  138. <div class="line"> <span class="stringliteral">&quot;@param filename File to determine length of.\n&quot;</span></div>
  139. <div class="line"> <span class="stringliteral">&quot;@returns Length in milliseconds.&quot;</span>)</div>
  140. <div class="line"> </div>
  141. <div class="line"><span class="comment">// A function group...</span></div>
  142. <div class="line">ConsoleFunctionGroupBegin(Example, &quot;This is an example group! Notice that the name for the group&quot;</div>
  143. <div class="line"> &quot;must be a valid identifier, due to limitations in the C preprocessor.&quot;);</div>
  144. <div class="line"> </div>
  145. <div class="line"><span class="comment">// ConsoleFunction definitions go here.</span></div>
  146. <div class="line"> </div>
  147. <div class="line">ConsoleFunctionGroupEnd(Example);</div>
  148. <div class="line"> </div>
  149. <div class="line"><span class="comment">// You can do similar things with methods...</span></div>
  150. <div class="line">ConsoleMethodGroupBegin(<a class="code hl_class" href="class_sim_set.html">SimSet</a>, UsefulFuncs, &quot;Here are some useful functions involving a <a class="code hl_class" href="class_sim_set.html">SimSet</a>.&quot;);</div>
  151. <div class="line">ConsoleMethod(<a class="code hl_class" href="class_sim_set.html">SimSet</a>, listObjects, <span class="keywordtype">void</span>, 2, 2, &quot;set.listObjects();&quot;)</div>
  152. <div class="line">ConsoleMethodGroupEnd(<a class="code hl_class" href="class_sim_set.html">SimSet</a>, UsefulFuncs, &quot;Here are some more useful functions involving a <a class="code hl_class" href="class_sim_set.html">SimSet</a>.&quot;);</div>
  153. <div class="ttc" id="aclass_sim_set_html"><div class="ttname"><a href="class_sim_set.html">SimSet</a></div><div class="ttdef"><b>Definition</b> simSet.h:102</div></div>
  154. </div><!-- fragment --><p><b>Examples using addField</b></p>
  155. <dl class="section note"><dt>Note</dt><dd>Using addCommand is strongly deprecated.</dd></dl>
  156. <div class="fragment"><div class="line"><span class="comment">// Example of a field group.</span></div>
  157. <div class="line">addGroup( <span class="stringliteral">&quot;Logging&quot;</span>, <span class="stringliteral">&quot;Things relating to logging.&quot;</span> );</div>
  158. <div class="line">addField( <span class="stringliteral">&quot;level&quot;</span>, TypeEnum, Offset( mLevel, <a class="code hl_class" href="class_console_logger.html">ConsoleLogger</a> ), 1, &amp;gLogLevelTable );</div>
  159. <div class="line">endGroup( <span class="stringliteral">&quot;Logging&quot;</span> );</div>
  160. </div><!-- fragment --><h1><a class="anchor" id="console_autodoc_makingdocs"></a>
  161. How to Generate Console Docs</h1>
  162. <p>Console docs can be generated by running the dumpConsoleFunctions() and dumpConsoleClasses(), then running the output through Doxygen. There is an example Doxygen configuration file to do this in HEAD, at doc\doxygen\html\script_doxygen.html.cfg. Doxygen will parse the psuedo-C++ generated by the console doc code and produce a class hierarchy and documentation of the global namespace. You may need to tweak the paths in the configuration file slightly to reflect your individual setup.</p>
  163. <h1><a class="anchor" id="console_autodoc_internals"></a>
  164. Console Auto-Documentation Internals</h1>
  165. <p>The consoleDoc system works by inserting "hidden" entries in <a class="el" href="class_namespace.html">Namespace</a> and <a class="el" href="class_abstract_class_rep.html">AbstractClassRep</a>; these hidden entries are assigned special type IDs so that they aren't touched by the standard name resolution code. At documentation creation time, the dumpConsole functions iterate through the <a class="el" href="class_namespace.html">Namespace</a> hierarchy and the <a class="el" href="class_abstract_class_rep.html">AbstractClassRep</a> data and extract this "hidden" information, outputting it in a Doxygen-compatible format.</p>
  166. <dl class="section note"><dt>Note</dt><dd>You can customize the output of the console documentation system by modifying these functions:<ul>
  167. <li>printClassHeader()</li>
  168. <li>printClassMethod()</li>
  169. <li>printGroupStart()</li>
  170. <li>printClassMember()</li>
  171. <li>printGroupEnd()</li>
  172. <li>printClassFooter()</li>
  173. </ul>
  174. </dd>
  175. <dd>
  176. There was once support for 'overloaded' script functions; ie, script functions with multiple usage strings. Certain functions in the audio library used this. However, it was deemed too complex, and removed from the scripting engine. There are still some latent traces of it, however. </dd></dl>
  177. </div></div><!-- contents -->
  178. </div><!-- PageDoc -->
  179. <!-- start footer part -->
  180. <hr class="footer"/><address class="footer"><small>
  181. Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
  182. </small></address>
  183. </body>
  184. </html>