Module:VarsUtil

local util_args = require ('Module:ArgsUtil')

local p = {}

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

function p.setVar(var, val, f)	if not f then f = mw.getCurrentFrame end f:callParserFunction('#vardefine:' .. var, val) return end

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

function p.resetGlobalIndex(name, f, val) if not f then f = mw.getCurrentFrame end f:callParserFunction('#vardefine:luaGlobalIndex' .. name, val or 0) return val or 0 end

function p.setGlobalIndex(name, f)	if not f then f = mw.getCurrentFrame end local n = (tonumber(f:callParserFunction('#var','luaGlobalIndex' .. name) or 0) or 0) + 1 f:callParserFunction('#vardefine:luaGlobalIndex' .. name, n)	return n end

function p.getGlobalIndex(name, f)	if not f then f = mw.getCurrentFrame end return tonumber(f:callParserFunction('#var','luaGlobalIndex' .. name) or 0) or 0 end

return p