Torque3D Documentation / _generateds / Script Auto-Documentation

Script Auto-Documentation

More...

Detailed Description

Using Script Auto-Documentation

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.

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.

note:

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.

The script 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.

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.tscript 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:

note:

You may want to add this code, or code like it, to your project if you have rewritten the script code in common.

// Writes out all script functions to a file
function writeOutFunctions() {
   new ConsoleLogger( logger, "ConsoleFunctions.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...

note:

It is of the utmost important that you keep your usage strings up to date! 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.

There are four types of items which can be documented using the autodocumentation system:

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

note:

Using addCommand is strongly deprecated.

// Example of a field group.
addGroup( "Logging", "Things relating to logging." );
addField( "level",   TYPEID< ConsoleLogLevel >(),     Offset( mLevel,    ConsoleLogger ) );
endGroup( "Logging" );

How to Generate Script Docs

Script 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 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.

Script Auto-Documentation Internals

The 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.

note:

You can customize the output of the console documentation system by modifying these functions:

note:

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.