跳转到内容

模組:Class

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

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

local class = 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)

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

end

local function getIdx(text)

	if text == nil then
		return #list
	end
	
	for idx, v in ipairs(list) do
		if isThisIdx(idx, text) then
			return idx
		end
	end

	return #list
	
end

p = {}

p.colour = makeInvokeFunc('_colour')

function p._colour(args)
	local text = string.lower(args[1])
	local idx = getIdx(text)
	
	return list[idx].colour
end

p.icon = makeInvokeFunc('_icon')

function p._icon(args)
	local text = string.lower(args[1])
	local idx = getIdx(text)
	
	return list[idx].icon
end

p.main = makeInvokeFunc('_main')

function p._main(args)
	return 
end

return p