模块:Foo
跳到导航
跳到搜索
此模块的文档可以在模块:Foo/doc创建
--p
local p = {}
function p.applicabletemplates(frame)
--获取外部参数
local args = frame.args
--方法-分割字符串
local function split(input, delimiter)
input = tostring(input)
delimiter = tostring(delimiter)
if (delimiter == '') then return false end
local pos, arr = 0, {}
-- for each divider found
for st, sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(input, pos))
return arr
end
--方法-排除数组指定元素
local function aryRemove(ary1, ary2)
local aryText = ""
--根据排除长度循环
for k = 1, #ary2, 1 do
--根据值长度循环
for i = 1, #ary1, 1 do
if (ary1[i] == ary2[k]) then
table.remove(ary1, i)
end
end
end
aryText = ary1
return aryText
end
--方法-超链接
local function link(url, name)
local res = ''
res = '[[' .. url .. '|' .. name .. ']]'
return res
end
-- assuming sample call
--获取数组
local templateIndex = split(args[1], ";")
local templateIndex2 = split(args[2], ";")
local templateRemove = split(args[3], ";")
--最终值
local tempAry = aryRemove(templateIndex2, templateRemove)
--html初始化
local html = ""
--html生成
--父结构
for i = 1, #templateIndex, 1 do
local tempUrlName = "游戏模板:"
tempUrlName = tempUrlName .. templateIndex[i]
html = html .. "<tr><td>" .. link(tempUrlName, string.gsub(tempUrlName, "游戏模板:", ""))
html = html .. "</td><td>"
if (#tempAry ~= 1) then
--子结构
for i = 1, #tempAry, 1 do
html = html .. link(tempAry[i], string.gsub(tempAry[i], "游戏模板:", ""))
if (i ~= #tempAry) then
html = html .. ", "
end
end
else
html = html .. "无"
end
html = html .. "</td></tr>"
end
--返回html结构
return html
end
--最终返回值p
return p