跳转到内容

模組:Class

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由風中的刀劍留言 | 贡献2015年8月19日 (三) 11:55编辑。这可能和当前版本存在着巨大的差异。

local list = mw.loadData('Module:Class/data')

local getArgs = require('Module:Arguments').getArgs

local function makeInvokeFunc(funcName)
	return function (frame)
		local args = getArgs(frame)
		return p[funcName](args)
	end
end

local function isThisIdx(idx, text)
	text = string.lower(text)
	
	if text == list[idx].code then
		return true
	end
	
	if text == list[idx].name then
		return true
	end
	
	for i, v in ipairs(list[idx].alias) do
		if text == v then return true end
	end
	
end

p = {}

p.colour = makeInvokeFunc('_colour')

function p._colour(args)
	local text = args[1]
	
	if text == nil then
		return list[#list].color
	end
	
	for idx, v in ipairs(list) do
		if isThisIdx(idx, text) then
			return v.color
		end
	end
	
	return list[31].color
end

return p