模块:图标
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:图标/doc创建
local p={}
function p.expandSet(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local str = args['str'] or '' -- 待处理字符串
local pname = args['pname'] or '' -- 输出参数名称
if (str=='' or pname=='') then
return ''
end
local paratable = {}
local result = ''
local strtable = mw.text.split(str, '、')
local itemtable = {}
local itemname, itemcount = '', 0
for i = 1, #strtable do
itemtable = mw.text.split(strtable[i],'*')
itemname = itemtable[1]
paratable[#paratable+1] = itemname
end
local parastr = table.concat(paratable,'、')
result = frame:callParserFunction{ name = '#set', args = { pname..'='..parastr,'+sep=、'} }
mw.log(result)
return result
end
function p.expandTemplate(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local str = args['str'] or '' -- 待处理字符串
if (str=='') then
return ''
end
local ptype = args['ptype'] or '' -- 图标模板类型
local sep = args['sep'] or '' -- 输出的分隔符
local paratable = {}
local resulttable = {}
local result = ''
local strtable = mw.text.split(str, '、')
local itemtable = {}
local itemname, itemcount = '', 0
for i = 1, #strtable do
itemtable = mw.text.split(strtable[i],'*')
itemname = itemtable[1]
itemcount = itemtable[2]
if (ptype=='') then
resulttable[#resulttable+1] = frame:expandTemplate{ title = '图标', args = { itemname, itemcount} }
else
resulttable[#resulttable+1] = frame:expandTemplate{ title = '图标', args = { ptype, itemname, itemcount} }
end
end
result = table.concat(resulttable,sep)
mw.log(result)
return result
end
return p