Documentation Guidelines
NutScript Wiki uses a modified version of LDoc to automatically generate markdown outputs. As such, a strict template must be used to ensure that all the documentation is generated properly.
Beginning of the documented .lua file
Struct Summary and Description
The first thing required in a documented file is a brief summmary and description of the module/class/etc. being documented.
The summary consists of a single sentence and MUST end with a period. It appears in the reference sheet to explain what the struct is and does.
The description can contain additional information about the struct, with detailed information, examples and warnings. The description only appears in the struct's documentation page.
The best way to format the summary and description are within a code block.
Module Declaration
Each .lua file that contains documented structs/functions must begin with a module declaration.
Valid declarations are:
Declaration | Description |
---|---|
@module |
A library, such as nut.char or nut.config |
@classmod |
A class, such as Character or Inventory |
@hook |
A collection of functions that can be used in hooks, such as GM:Nick(client) |
Additionally, the struct name is required, after the declaration type. This will be the name under which the documentation will save under.
Documenting Functions
Function Description
All functions that required generated documentation must start with a comment with 3 dashes (---
) with a description of the function.
Realm
All functions exist within a realm, either client
, server
, or shared
(both). The realm of the function can be defined with the --@realm
tag. If omitted, the realm is assumed to be shared
by default.
Arguments
Each argument required by the function needs to be documented per line. The tag depends on the argument type:
Tag | Argument |
---|---|
-- @int |
An integer |
-- @number |
A generic number, can be a float |
-- @string |
A string |
-- @bool |
A boolean |
-- @tab |
A table |
-- @func |
A function |
-- @entity |
An Entity |
-- @client |
A Client Entity (ie Player) |
-- @character |
A NutScript character object |
-- @vector |
A Vector object |
-- @angle |
An Angle object |
-- @param |
A generic parameter without a specific type. The type specified will be "vararg" |
-- @tparam [type] |
A parameter with a custom type. The type name comes before the argument name |
After the tag, the name of the argument is defined, followed by its description.
@tparam type and name
When using @tparam
, the custom type comes before the name.
Optional and Default Arguments
If an argument is optional, the [opt]
modifier is added. If the argument has a default value if none is provided, the [opt='default']
modifier is used, where 'default'
is the default value.
Returns
If the function has one or more return values, you can use the -- @return
tag. If the returned value has a specific type, use -- @treturn [type]
instead
Usage
If you want to provide a usage example of the function, you can use the -- @usage
tag.
If the usage example can fit in a single line, the example can be typed in the same line as the tag
Alternatively, if you require more than one line, for instance for context, comments until the next tag will be used in the usage example
Other tags
-- @internal
marks the function as internal (This is used internally - although you're able to use it you probably shouldn't.)-- @see
links to other documentation, for context or further usage-- @pluginwarning [pluginName]
adds a warning that the function is defined within a plugin, and as such its functionality might differ in different schemas
Sections
Sometimes, especially with plugins, you may need to manually define sections within a file, for instance when meta-methods are located between library functions. You can easily define a new section with the -- @section
tag. If a section tag appears multiple times within a file, the documented functions will be sorted into one place.
Result
The example documentation above would provide the following result on the developer wiki
inventory:exampleFunc (a, b, c)
sh_inventory:exampleFunc
A function that takes 3 number arguments
Parameters:
integer a optional. default: 2 the numerator, which if not provided, will use 2 as a defaultinteger b the denominator
integer c optional the optional rounding number
Returns:
number a returned numberanother custom returned value that doesn't have a specific type