“模块:PageName”的版本间的差异
跳到导航
跳到搜索
标签:撤销 |
|||
| 第1行: | 第1行: | ||
| − | |||
| − | |||
local p = {} | local p = {} | ||
| − | function p. | + | function p.split(s) |
| − | |||
| − | |||
| − | |||
local parent, name | local parent, name | ||
| − | + | parent, name = s:match("^(.+)/(.+)$") | |
| − | + | return parent, name | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | return | ||
end | end | ||
| − | function | + | function p.rsplit(s) |
| − | + | return s:match("^([^/]+)/(.+)$") | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | + | local type2name = { | |
| − | + | ['W'] = "世界观", | |
| − | + | ['X'] = "联动" | |
| − | + | } | |
| − | |||
| − | |||
| − | function | + | function p.type_name(s) |
| − | + | return type2name[s] | |
| − | |||
| − | |||
| − | |||
| − | return | ||
end | end | ||
| − | function | + | function p.parse(s) |
| − | + | local type_flag, full_name | |
| − | + | type_flag, full_name = s:match("^([XW])/(.+)$") | |
| − | + | if type_flag then | |
| − | + | local base, sub | |
| − | + | base, sub = p.rsplit(full_name) | |
| − | + | if base then | |
| − | + | return type_flag, base, sub | |
| − | + | else | |
| − | local | + | return type_flag, full_name, nil |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | local | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | if | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | else | ||
| − | |||
| − | |||
end | end | ||
| + | else | ||
| + | return nil, nil, s | ||
end | end | ||
| − | |||
end | end | ||
| − | + | function p.getPageName() | |
| − | + | return mw.title.getCurrentTitle().text | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
| − | |||
return p | return p | ||
2021年7月5日 (一) 08:07的最新版本
此模块的文档可以在模块:PageName/doc创建
local p = {}
function p.split(s)
local parent, name
parent, name = s:match("^(.+)/(.+)$")
return parent, name
end
function p.rsplit(s)
return s:match("^([^/]+)/(.+)$")
end
local type2name = {
['W'] = "世界观",
['X'] = "联动"
}
function p.type_name(s)
return type2name[s]
end
function p.parse(s)
local type_flag, full_name
type_flag, full_name = s:match("^([XW])/(.+)$")
if type_flag then
local base, sub
base, sub = p.rsplit(full_name)
if base then
return type_flag, base, sub
else
return type_flag, full_name, nil
end
else
return nil, nil, s
end
end
function p.getPageName()
return mw.title.getCurrentTitle().text
end
return p