Fandom

Wikia Developers Wiki

Global Lua Modules/Codedoc

< Global Lua Modules

861pages on
this wiki
Add New Page
Talk0 Share

Automatically creates documentation of a Lua module by extracting its documentation markup.

Usage

This module makes use of the syntax defined in ExpLua to retrieve documentation for a module. For example, with Module:codedoc/sample one could use the following Lua invoke in a talk page to show its code:

{{#invoke:codedoc|main|Module:codedoc/sample}}

See generated docs in Module talk:Codedoc/sample.

Syntax

The syntax is:

{{#invoke:codedoc|main|modulename}}

The module name must contain the syntax as described, otherwise it will not retrieve anything.

Documentation syntax

As described by the ExpLua author[1]:

For the whole file:

--| Begins a module/file comment, e.g., "this file does *this*".
--by Pedro Miller Rabinovitch <miller@inf.puc-rio.br>
--$Id: myfile.lua,v 1.12 2003/10/17 00:13:56 miller Exp $
--TODO lots of stuff.

(Both --by and --TODO can be abbreviated to --b and --T)

Preceding each function:

--% This is the purpose of the function, i.e., what it *does*.
--- And this is the second line, which will concatenated to
--- the others.
--@ first (string) Text of the first parameter
--@ what (table) The second parameter is the table used for an
--- example
--@ [...] (any) Optional parameters to the called whatever
--: (number) Number of whatevers done or nil if an error occured
function Module:MyFunction( first, what, ... )

Description

The syntax relies on adding comments with special characters that have a specific meaning, as described below:

  • --| — is used to describe the module itself
  • --by — contains author info
  • --TODO — contains any todo notes
  • --% — describes the purpose of the function
  • --@ — contains information about the parameters (format: "parameter name (parameter type) description")
  • --: — contains the description of the values returned by a function (format: "return type and description")

Note that by default the module details (author, etc.) are hidden by a setting in the script, but this can be overwritten.

Install

Installing modules

To get a brief introduction to lua read the basics page first. On Wikia, one can use modules by either accessing a module remotely or copying all its contents to a Wiki. Modules accessed remotely from dev.wikia are subject to change while 'correctly' copied modules are controlled by a particular wiki.

Using a module "remotely" using Module:Devmodule

Create Module:Devmodule and copy the following code to remotely access modules in dev's repository. See more details in Global Lua Modules/Devmodule.
--[[This imports modules from dev.wikia]]
return require("Dev:Devmodule")

Loading modules remotely from dev.wikia

Create Module:Codedoc in your wiki and add the following code:
--This loads modules directly from dev.wikia.com
return require("Dev:Codedoc")

Using Module:Codedoc in another wiki

To use modules without depending on dev see this page. Create Template:Codedoc in your wiki and add the following code:
{{#invoke:Codedoc|main}}

Using template in a page

You can use this module in a page using syntax such as:
{{Codedoc|main|arg1|arg2}}

Module information

Functions

p.createDocs

Creates docs for a module..
Parameters
NameTypepurpose
pagestringA page to read the docs from e.g. Bananas.
Return typeReturn purpose
stringA string containing the documentation of a module.

createFunctionTables

Creates tables contains function parameters and return types..
Parameters
NameTypepurpose
functionTabletableA table containing all functions in the code, related docs.
Return typeReturn purpose
tableA table based on mw.html containing the function docs.

p.main

Entry point for documenting..
Parameters
NameTypepurpose
frametableA frame object containing a module name as first parameter.
Return typeReturn purpose
stringThe documentation of a particular module.

getDefaultPage

Gets a default mpage, generally a subpage(e.g"/links") of "Global lua modules"..
Return typeReturn purpose
stringThe default page containing documentation.

References

  1. http://lua-users.org/wiki/ExpLua

Start a Discussion Discussions about Global Lua Modules/Codedoc

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.