consoleDoc.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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.cc
  23. /// @page console_autodoc Console Auto-Documentation
  24. ///
  25. /// @see consoleDoc.cc
  26. ///
  27. /// @section console_autodoc_using Using Console Auto-Documentation
  28. ///
  29. /// There are on the order of three hundred functions exposed to the script language
  30. /// through the console. It is therefore extremely important that they be documented,
  31. /// but due to their number, it is difficult to maintain a seperate reference document.
  32. ///
  33. /// Therefore, a simple documentation system has been built into the scripting engine. It
  34. /// was initially added by Mark Frohnmayer, and later enhanced by Ben Garney. The
  35. /// scripting engine supports grouping functions and methods, to help organize the
  36. /// several hundred functions, as well as associating a "usage string" with functions and
  37. /// groups.
  38. ///
  39. /// @note The results of a console doc dump will vary depending on when you run it. If
  40. /// you run it, for example, while in the game menu, it won't output any data for
  41. /// the script-defined classes which are defined for gameplay. To get comprehensive
  42. /// documentation, you may need to write a special script that will get all your
  43. /// classes loaded into the scripting engine.
  44. ///
  45. /// The console documentation system is designed to output a dump of the current state
  46. /// of the scripting engine in a format understandable by Doxygen. It does this by
  47. /// traversing the namespace/class hierarchy in memory at the time of the dump, and
  48. /// outputting psuedo-C++ code equivalent to this class hierarchy.
  49. ///
  50. /// @subsection console_autodoc_using_script For the Scripter...
  51. ///
  52. /// Currently, there is no way to associate usage strings or other documentation with script code
  53. /// like you can with C++ code.
  54. ///
  55. /// You can get a list of all the methods and fields of an object from any object which inherits
  56. /// from SimObject (ie, every object), as well as the documentation on those objects by using the
  57. /// dump() method from the console:
  58. ///
  59. /// @code
  60. /// ==>$foo = new SimObject();
  61. /// ==>$foo.dump();
  62. /// Member Fields:
  63. /// Tagged Fields:
  64. /// Methods:
  65. /// delete() - obj.delete()
  66. /// dump() - obj.dump()
  67. /// getClassName() - obj.getClassName()
  68. /// getGroup() - obj.getGroup()
  69. /// getId() - obj.getId()
  70. /// getName() - obj.getName()
  71. /// getType() - obj.getType()
  72. /// save() - obj.save(fileName, <selectedOnly>)
  73. /// schedule() - object.schedule(time, command, <arg1...argN>);
  74. /// setName() - obj.setName(newName)
  75. /// @endcode
  76. ///
  77. /// In the Torque example app, there are two functions defined in common\\client\\scriptDoc.cs
  78. /// which automate the process of dumping the documentation. They make use of the ConsoleLogger
  79. /// object to output the documentation to a file, and look like this:
  80. ///
  81. /// @note You may want to add this code, or code like it, to your project if you have
  82. /// rewritten the script code in common.
  83. ///
  84. /// @code
  85. /// // Writes out all script functions to a file
  86. /// function writeOutFunctions() {
  87. /// new ConsoleLogger( logger, "scriptFunctions.txt", false );
  88. /// dumpConsoleFunctions();
  89. /// logger.delete();
  90. /// }
  91. ///
  92. /// // Writes out all script classes to a file
  93. /// function writeOutClasses() {
  94. /// new ConsoleLogger( logger, "scriptClasses.txt", false );
  95. /// dumpConsoleClasses();
  96. /// logger.delete();
  97. /// }
  98. /// @endcode
  99. ///
  100. /// @subsection console_autodoc_using_coder For the C++ Coder...
  101. ///
  102. /// @note <b>It is of the utmost important that you keep your usage strings up to date!</b>
  103. /// Usage strings are the only way that a scripter has to know how to use the methods,
  104. /// functions, and variables you expose. Misleading, missing, or out of date documentation
  105. /// will make their lives much harder - and yours, too, because you'll have to keep
  106. /// explaining things to them! So make everyone's lives easier - keep your usage strings
  107. /// clear, concise, and up to date.
  108. ///
  109. /// There are four types of items which can be documented using the autodocumentation system:
  110. /// - <b>Fields</b>, which are defined using the addField() calls. They are documented
  111. /// by passing a string to the usage parameter.
  112. /// - <b>Field groups</b>, which are defined using the beginGroup() and endGroup() calls.
  113. /// They are documented by passing a descriptive string to the usage parameter.
  114. /// - <b>Method groups</b>, which are defined using beginCommandGroup(), endCommandGroup(),
  115. /// ConsoleMethodGroupEnd(), ConsoleMethodGroupBegin(), ConsoleFunctionGroupEnd(), and
  116. /// ConsoleFunctionGroupBegin().
  117. /// - <b>Methods and functions</b>, which are defined using either SimObject::addCommand(),
  118. /// the ConsoleMethod() macro, or the ConsoleFunction() macro. Methods and functions are
  119. /// special in that the usage strings should be in a specific format, so
  120. /// that parameter information can be extracted from them and placed into the Doxygen
  121. /// output.
  122. ///
  123. /// You can use standard Doxygen commands in your comments, to make the documentation clearer.
  124. /// Of particular use are \@returns, \@param, \@note, and \@deprecated.
  125. ///
  126. /// <b>Examples using global definitions.</b>
  127. ///
  128. /// @code
  129. /// // Example of using Doxygen commands.
  130. /// ConsoleFunction(alxGetWaveLen, S32, 2, 2, "(string filename)"
  131. /// "Get length of a wave file\n\n"
  132. /// "@param filename File to determine length of.\n"
  133. /// "@returns Length in milliseconds.")
  134. ///
  135. /// // A function group...
  136. /// ConsoleFunctionGroupBegin(Example, "This is an example group! Notice that the name for the group"
  137. /// "must be a valid identifier, due to limitations in the C preprocessor.");
  138. ///
  139. /// // ConsoleFunction definitions go here.
  140. ///
  141. /// ConsoleFunctionGroupEnd(Example);
  142. ///
  143. /// // You can do similar things with methods...
  144. /// ConsoleMethodGroupBegin(SimSet, UsefulFuncs, "Here are some useful functions involving a SimSet.");
  145. /// ConsoleMethod(SimSet, listObjects, void, 2, 2, "set.listObjects();")
  146. /// ConsoleMethodGroupEnd(SimSet, UsefulFuncs, "Here are some more useful functions involving a SimSet.");
  147. /// @endcode
  148. ///
  149. /// <b>Examples using addField</b>
  150. ///
  151. /// @note Using addCommand is strongly deprecated.
  152. ///
  153. /// @code
  154. /// // Example of a field group.
  155. /// addGroup( "Logging", "Things relating to logging." );
  156. /// addField( "level", TypeEnum, Offset( mLevel, ConsoleLogger ), 1, &gLogLevelTable );
  157. /// endGroup( "Logging" );
  158. /// @endcode
  159. ///
  160. /// @section console_autodoc_makingdocs How to Generate Console Docs
  161. ///
  162. /// Console docs can be generated by running the dumpConsoleFunctions() and
  163. /// dumpConsoleClasses(), then running the output through Doxygen. There is an
  164. /// example Doxygen configuration file to do this in HEAD,
  165. /// at doc\\doxygen\\html\\script_doxygen.html.cfg. Doxygen will parse the psuedo-C++
  166. /// generated by the console doc code and produce a class hierarchy and documentation
  167. /// of the global namespace. You may need to tweak the paths in the configuration file
  168. /// slightly to reflect your individual setup.
  169. ///
  170. /// @section console_autodoc_internals Console Auto-Documentation Internals
  171. ///
  172. /// The consoleDoc system works by inserting "hidden" entries in Namespace and
  173. /// AbstractClassRep; these hidden entries are assigned special type IDs so that
  174. /// they aren't touched by the standard name resolution code. At documentation
  175. /// creation time, the dumpConsole functions iterate through the Namespace hierarchy
  176. /// and the AbstractClassRep data and extract this "hidden" information, outputting
  177. /// it in a Doxygen-compatible format.
  178. ///
  179. /// @note You can customize the output of the console documentation system by modifying
  180. /// these functions:
  181. /// - printClassHeader()
  182. /// - printClassMethod()
  183. /// - printGroupStart()
  184. /// - printClassMember()
  185. /// - printGroupEnd()
  186. /// - printClassFooter()
  187. ///
  188. /// @note There was once support for 'overloaded' script functions; ie, script functions
  189. /// with multiple usage strings. Certain functions in the audio library used this.
  190. /// However, it was deemed too complex, and removed from the scripting engine. There
  191. /// are still some latent traces of it, however.