FANDOM


--
-- Module that provides an interface with [[mw:Extension:Variables]]
-- You can use this to pass variables between modules/invokes
--
 
local var = {}
 
--- Define a variable
--
-- @param varname Name of the var to declare
-- @param value   Value of the new var, if not provided, assumes the empty string
function var.define( varname, value )
	if not varname then return end
	if value == nil then value = '' else value = tostring(value) end
 
	mw.getCurrentFrame():preprocess('{{#vardefine:'..varname..'|'..value..'}}')
end
 
--- Get a variable
--
-- @param varname      Name of the variable to get
-- @param defaultvalue Default value in case the variable is not yet defined
-- @return string
function var.get( varname, defaultvalue )
	if not varname then return '' end
	if defaultvalue then defaultvalue = '|' .. tostring(defaultvalue) else defaultvalue = '' end
 
	return tostring( mw.getCurrentFrame():preprocess('{{#var:'..varname..defaultvalue..'}}') )
end
 
--- Check if a variable exists
--
-- @param varname Name of the variable to check
-- @return boolean
function var.exists( varname )
	if not varname then return false end
 
	local res = tostring( mw.getCurrentFrame():preprocess('{{#varexists:'..varname..'}}') )
	return res == '1' and true or false
end
 
return var

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.