Module:Variables

-- Imports

local util = require( 'libraryUtil' ) local checkType = util.checkType local checkTypeMulti = util.checkTypeMulti

-- Helper functions

local frame

local function callParserFunction( func, args ) if not frame then frame = mw.getCurrentFrame end return frame:callParserFunction( func, args ) end

-- Functions

local p = {}

function p.vardefine( name, value ) checkType( 'vardefine', 1, name, 'string' ) checkTypeMulti( 'vardefine', 2, value, { 'boolean', 'string', 'number', 'nil' } ) local value = tostring( value or '' )

callParserFunction( '#vardefine', { name, value } ) end

function p.vardefineecho( name, value ) checkType( 'vardefineecho', 1, name, 'string' ) checkTypeMulti( 'vardefineecho', 2, value, { 'boolean', 'string', 'number', 'nil' } ) local value = tostring( value or '' )

return callParserFunction( '#vardefineecho', { name, value } ) end

function p.varexists( name ) checkType( 'varexists', 1, name, 'string' )

return ( callParserFunction( '#varexists', name ) == '1' ) end

function p.var( name, default ) checkType( 'var', 1, name, 'string' )

local value = callParserFunction( '#var', name ) if value ~= '' then return value elseif default then return default else return nil end end

-- Return

return p