consoleDoc.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // This file exists solely to document consoleDoc.cpp
  23. /// @defgroup script_autodoc Script Auto-Documentation
  24. /// @ingroup console_system Console System
  25. ///
  26. /// @section script_autodoc_using Using Script Auto-Documentation
  27. ///
  28. /// There are on the order of three hundred functions exposed to the script language
  29. /// through the console. It is therefore extremely important that they be documented,
  30. /// but due to their number, it is difficult to maintain a seperate reference document.
  31. ///
  32. /// Therefore, a simple documentation system has been built into the scripting engine. It
  33. /// was initially added by Mark Frohnmayer, and later enhanced by Ben Garney. The
  34. /// scripting engine supports grouping functions and methods, to help organize the
  35. /// several hundred functions, as well as associating a "usage string" with functions and
  36. /// groups.
  37. ///
  38. /// @note The results of a console doc dump will vary depending on when you run it. If
  39. /// you run it, for example, while in the game menu, it won't output any data for
  40. /// the script-defined classes which are defined for gameplay. To get comprehensive
  41. /// documentation, you may need to write a special script that will get all your
  42. /// classes loaded into the scripting engine.
  43. ///
  44. /// The script documentation system is designed to output a dump of the current state
  45. /// of the scripting engine in a format understandable by Doxygen. It does this by
  46. /// traversing the namespace/class hierarchy in memory at the time of the dump, and
  47. /// outputting psuedo-C++ code equivalent to this class hierarchy.
  48. ///
  49. /// @subsection script_autodoc_using_script For the Scripter...
  50. ///
  51. /// Currently, there is no way to associate usage strings or other documentation with script code
  52. /// like you can with C++ code.
  53. ///
  54. /// You can get a list of all the methods and fields of an object from any object which inherits
  55. /// from SimObject (ie, every object), as well as the documentation on those objects by using the
  56. /// dump() method from the console:
  57. ///
  58. /// @code
  59. /// ==>$foo = new SimObject();
  60. /// ==>$foo.dump();
  61. /// Member Fields:
  62. /// Tagged Fields:
  63. /// Methods:
  64. /// delete() - obj.delete()
  65. /// dump() - obj.dump()
  66. /// getClassName() - obj.getClassName()
  67. /// getGroup() - obj.getGroup()
  68. /// getId() - obj.getId()
  69. /// getName() - obj.getName()
  70. /// getType() - obj.getType()
  71. /// save() - obj.save(fileName, <selectedOnly>)
  72. /// schedule() - object.schedule(time, command, <arg1...argN>);
  73. /// setName() - obj.setName(newName)
  74. /// @endcode
  75. ///
  76. /// In the Torque example app, there are two functions defined in common\\client\\scriptDoc.tscript
  77. /// which automate the process of dumping the documentation. They make use of the ConsoleLogger
  78. /// object to output the documentation to a file, and look like this:
  79. ///
  80. /// @note You may want to add this code, or code like it, to your project if you have
  81. /// rewritten the script code in common.
  82. ///
  83. /// @code
  84. /// // Writes out all script functions to a file
  85. /// function writeOutFunctions() {
  86. /// new ConsoleLogger( logger, "ConsoleFunctions.txt", false );
  87. /// dumpConsoleFunctions();
  88. /// logger.delete();
  89. /// }
  90. ///
  91. /// // Writes out all script classes to a file
  92. /// function writeOutClasses() {
  93. /// new ConsoleLogger( logger, "scriptClasses.txt", false );
  94. /// dumpConsoleClasses();
  95. /// logger.delete();
  96. /// }
  97. /// @endcode
  98. ///
  99. /// @subsection script_autodoc_using_coder For the C++ Coder...
  100. ///
  101. /// @note <b>It is of the utmost important that you keep your usage strings up to date!</b>
  102. /// Usage strings are the only way that a scripter has to know how to use the methods,
  103. /// functions, and variables you expose. Misleading, missing, or out of date documentation
  104. /// will make their lives much harder - and yours, too, because you'll have to keep
  105. /// explaining things to them! So make everyone's lives easier - keep your usage strings
  106. /// clear, concise, and up to date.
  107. ///
  108. /// There are four types of items which can be documented using the autodocumentation system:
  109. /// - <b>Fields</b>, which are defined using the addField() calls. They are documented
  110. /// by passing a string to the usage parameter.
  111. /// - <b>Field groups</b>, which are defined using the beginGroup() and endGroup() calls.
  112. /// They are documented by passing a descriptive string to the usage parameter.
  113. /// - <b>Method groups</b>, which are defined using beginCommandGroup(), endCommandGroup(),
  114. /// ConsoleMethodGroupEnd(), ConsoleMethodGroupBegin(), ConsoleFunctionGroupEnd(), and
  115. /// ConsoleFunctionGroupBegin().
  116. /// - <b>Methods and functions</b>, which are defined using either SimObject::addCommand(),
  117. /// the ConsoleMethod() macro, or the ConsoleFunction() macro. Methods and functions are
  118. /// special in that the usage strings should be in a specific format, so
  119. /// that parameter information can be extracted from them and placed into the Doxygen
  120. /// output.
  121. ///
  122. /// You can use standard Doxygen commands in your comments, to make the documentation clearer.
  123. /// Of particular use are \@returns, \@param, \@note, and \@deprecated.
  124. ///
  125. /// <b>Examples using global definitions.</b>
  126. ///
  127. /// @code
  128. /// // Example of using Doxygen commands.
  129. /// ConsoleFunction(alxGetWaveLen, S32, 2, 2, "(string filename)"
  130. /// "Get length of a wave file\n\n"
  131. /// "@param filename File to determine length of.\n"
  132. /// "@returns Length in milliseconds.")
  133. ///
  134. /// // A function group...
  135. /// ConsoleFunctionGroupBegin(Example, "This is an example group! Notice that the name for the group"
  136. /// "must be a valid identifier, due to limitations in the C preprocessor.");
  137. ///
  138. /// // ConsoleFunction definitions go here.
  139. ///
  140. /// ConsoleFunctionGroupEnd(Example);
  141. ///
  142. /// // You can do similar things with methods...
  143. /// ConsoleMethodGroupBegin(SimSet, UsefulFuncs, "Here are some useful functions involving a SimSet.");
  144. /// ConsoleMethod(SimSet, listObjects, void, 2, 2, "set.listObjects();")
  145. /// ConsoleMethodGroupEnd(SimSet, UsefulFuncs, "Here are some more useful functions involving a SimSet.");
  146. /// @endcode
  147. ///
  148. /// <b>Examples using addField</b>
  149. ///
  150. /// @note Using addCommand is strongly deprecated.
  151. ///
  152. /// @code
  153. /// // Example of a field group.
  154. /// addGroup( "Logging", "Things relating to logging." );
  155. /// addField( "level", TYPEID< ConsoleLogLevel >(), Offset( mLevel, ConsoleLogger ) );
  156. /// endGroup( "Logging" );
  157. /// @endcode
  158. ///
  159. /// @section script_autodoc_makingdocs How to Generate Script Docs
  160. ///
  161. /// Script docs can be generated by running the dumpConsoleFunctions() and
  162. /// dumpConsoleClasses(), then running the output through Doxygen. There is an
  163. /// example Doxygen configuration file to do this at
  164. /// doc\\doxygen\\html\\script_doxygen.html.cfg. Doxygen will parse the psuedo-C++
  165. /// generated by the console doc code and produce a class hierarchy and documentation
  166. /// of the global namespace. You may need to tweak the paths in the configuration file
  167. /// slightly to reflect your individual setup.
  168. ///
  169. /// @section script_autodoc_internals Script Auto-Documentation Internals
  170. ///
  171. /// The consoleDoc system works by inserting "hidden" entries in Namespace and
  172. /// AbstractClassRep; these hidden entries are assigned special type IDs so that
  173. /// they aren't touched by the standard name resolution code. At documentation
  174. /// creation time, the dumpConsole functions iterate through the Namespace hierarchy
  175. /// and the AbstractClassRep data and extract this "hidden" information, outputting
  176. /// it in a Doxygen-compatible format.
  177. ///
  178. /// @note You can customize the output of the console documentation system by modifying
  179. /// these functions:
  180. /// - printClassHeader()
  181. /// - printClassMethod()
  182. /// - printGroupStart()
  183. /// - printClassMember()
  184. /// - printGroupEnd()
  185. /// - printClassFooter()
  186. ///
  187. /// @note There was once support for 'overloaded' script functions; ie, script functions
  188. /// with multiple usage strings. Certain functions in the audio library used this.
  189. /// However, it was deemed too complex, and removed from the scripting engine. There
  190. /// are still some latent traces of it, however.