Leaguepedia | League of Legends Esports Wiki
Advertisement

Edit the documentation or categories for this module.


local util_args = require ('Module:ArgsUtil')

local p = {}

function p.getVar(var)
	local val = mw.getCurrentFrame():callParserFunction('#var', var)
	if val == '' then
		return nil
	end
	return util_args.norm(val)
end

function p.getBool(var)
	local val = p.getVar(var)
	return util_args.castAsBool(val)
end

function p.setVar(var, val)
	mw.getCurrentFrame():callParserFunction('#vardefine:' .. var, val)
	return
end

function p.setVarOnlyIf(var, val)
	if not val then return end
	p.setVar(var, val)
end

function p.getGlobalIndex(name)
	local val = p.getVar('luaGlobalIndex' .. name)
	return tonumber(val or 0) or 0
end

function p.setGlobalIndex(name)
	local n = p.getGlobalIndex(name) + 1
	p.setVar('luaGlobalIndex' .. name, n)
	return n
end

function p.resetGlobalIndex(name, val)
	val = val or 0
	p.setVar('luaGlobalIndex' .. name, val)
	return val
end

function p.appendToList(name, val, sep)
	-- this is just for helping to debug and shouldn't actually be used ever probably
	sep = sep or ', '
	local old_val = p.getVar(name)
	p.setVar(name, old_val .. sep .. val)
end

function p.clearAll(tbl)
	for _, v in ipairs(tbl) do
		p.setVar(v, '')
	end
end

return p
Advertisement