Fandom

Wikia Developers Wiki

Global Lua Modules/Utility

< Global Lua Modules

847pages on
this wiki
Add New Page
Talk3 Share
This page documents a meta-module (Module:Utility) that consists of common and useful lua functions that can be used in many lua scripts.

Note: This module should imported using require. It is not meant to be used directly in a page or template (e.g.{{#invoke:). 

Using

These functions can only be accessed from another module.

For example:

Using a module

local u = require('Module:Utility')
 
function getmilliseconds()
   return u.getdate('2010-02-01')
end


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:Utility in your wiki and add the following code:
--This loads modules directly from dev.wikia.com
return require("Dev:Utility")

Using Module:Utility in another wiki

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

Using template in a page

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

Module information

Functions

p.getArgs

Put all arguments into a real table - Returns Parent, child args table..
Parameters
NameTypepurpose
frametableA frame object.
targetArgsstringthe target arguments to return, possible values ("parent", "child", "both".
Return typeReturn purpose
tableA table containing arguments.

p.fetchArgs

This is meant to fetch a args table..
Parameters
NameTypepurpose
tTmptableThe template args from the module {{#invoke.
Return typeReturn purpose
tableA table containing arguments or nil.

p.checkArgs

Check if args are enough for script to run..
Parameters
NameTypepurpose
frametableScribunto frame object.
iArgsnumberNumber of arguments required to run checkArgs.
bParentbooleanChecks parent (true) or child arguments..
Return typeReturn purpose
booleanTrue if args are enough for script to run.

p.addDays

Add days to date..
Parameters
NameTypepurpose
sDatestringDate string e.g. 2012-01-02, YYYY-MM-DD.
iDaysnumberNumber of days to add or subtract (negative or positive).
bReturnTablebooleanSet to true to returns a lua date table.
sFormatstringspecific format for date..
Return typeReturn purpose
stringA calculated date.

p.checkdate

Check if date is in appropriate format --Iso YYYY-MM-DD..
Parameters
NameTypepurpose
sDatestringDate string e.g. 2012-01-02, YYYY-MM-DD.
sPatstringA lua pattern for a date, default is (%d%d%d%d)-(%d%d)-(%d%d).
Return typeReturn purpose
booleanTrue for valid date.

p.isempty

Check if table is empty..
Parameters
NameTypepurpose
tTabtableA valid table.
Return typeReturn purpose
booleantrue for empty.

p.round

Round a number..
Parameters
NameTypepurpose
numnumberA number.
idpnumberDecimal points.
Return typeReturn purpose
numberRounded number..

p.datediff

Calculate difference between two dates..
Parameters
NameTypepurpose
sDate1stringA string containing a date.
sDate2stringA string containing a date.
isAbsolutebooleanabsolute number (no negatives).
Return typeReturn purpose
numberDifference between days number or null.

p.getdate

Get lua timestamp (os.time) using custom format..
Parameters
NameTypepurpose
sDatestringA string containing a date.
sPatstringA lua pattern, default: "(%d%d%d%d)-(%d%d)-(%d%d)".
Return typeReturn purpose
tableLua os.time.

p.table_print

Get a printed table..
Parameters
NameTypepurpose
tablenametableA simple lua table.
Return typeReturn purpose
stringA printed lua table.

p.debug

Gets debug information for a function using lua xpcall..
Parameters
NameTypepurpose
oFuncfunctionA function to debug.
bShowErrbooleanTrue to show error.
Return typeReturn purpose
stringA stacktrace containing error details.

p.log

Gets variable content..
Parameters
NameTypepurpose
oDatavariableA variable to output information (e.g. a table {}).
Return typeReturn purpose
stringPrints out variable content.

p.nowiki

Performs a nowiki on content..
Parameters
NameTypepurpose
frametableScribunto frame.
Return typeReturn purpose
stringPrints out nowiki of first argument.

See also

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.