![]() TGE Version 1.5.2 | |
| |
Console Auto-Documentation
Using Console Auto-DocumentationThere 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.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.
For the Scripter...Currently, there is no way to associate usage strings or other documentation with script code like you can with C++ code.You can get a list of all the methods and fields of an object from any object which inherits from SimObject (ie, every object), as well as the documentation on those objects by using the dump() method from the console:
==>$foo = new SimObject(); ==>$foo.dump(); Member Fields: Tagged Fields: Methods: delete() - obj.delete() dump() - obj.dump() getClassName() - obj.getClassName() getGroup() - obj.getGroup() getId() - obj.getId() getName() - obj.getName() getType() - obj.getType() save() - obj.save(fileName, <selectedOnly>) schedule() - object.schedule(time, command, <arg1...argN>); setName() - obj.setName(newName) In the Torque 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 ConsoleLogger object to output the documentation to a file, and look like this:
// Writes out all script functions to a file function writeOutFunctions() { new ConsoleLogger( logger, "scriptFunctions.txt", false ); dumpConsoleFunctions(); logger.delete(); } // Writes out all script classes to a file function writeOutClasses() { new ConsoleLogger( logger, "scriptClasses.txt", false ); dumpConsoleClasses(); logger.delete(); } For the C++ Coder...
You can use standard Doxygen commands in your comments, to make the documentation clearer. Of particular use are @returns, @param, @note, and @deprecated. Examples using global definitions.
// Example of using Doxygen commands. ConsoleFunction(alxGetWaveLen, S32, 2, 2, "(string filename)" "Get length of a wave file\n\n" "@param filename File to determine length of.\n" "@returns Length in milliseconds.") // A function group... ConsoleFunctionGroupBegin(Example, "This is an example group! Notice that the name for the group" "must be a valid identifier, due to limitations in the C preprocessor."); // ConsoleFunction definitions go here. ConsoleFunctionGroupEnd(Example); // You can do similar things with methods... ConsoleMethodGroupBegin(SimSet, UsefulFuncs, "Here are some useful functions involving a SimSet."); ConsoleMethod(SimSet, listObjects, void, 2, 2, "set.listObjects();") ConsoleMethodGroupEnd(SimSet, UsefulFuncs, "Here are some more useful functions involving a SimSet."); Examples using addField
// Example of a field group. addGroup( "Logging", "Things relating to logging." ); addField( "level", TypeEnum, Offset( mLevel, ConsoleLogger ), 1, &gLogLevelTable ); endGroup( "Logging" ); How to Generate Console DocsConsole 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.Console Auto-Documentation InternalsThe consoleDoc system works by inserting "hidden" entries in Namespace and AbstractClassRep; 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 Namespace hierarchy and the AbstractClassRep data and extract this "hidden" information, outputting it in a Doxygen-compatible format.
|