模块:Utils:修订间差异
来自星露谷物语扩展百科
更多操作
删除的内容 添加的内容
getArg |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local |
local p = {} |
||
function |
function p.getArg(input, index) |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
function p.hasChinese(str) |
|||
return type(str) == 'string' and string.match(str, "[\228-\233][\128-\191][\128-\191]") ~= nil |
|||
end |
|||
function p.LazyLoad(moduleName, toLowerCase) |
|||
toLowerCase = toLowerCase or false |
toLowerCase = toLowerCase or false |
||
local loaded = nil |
local loaded = nil |
||
| 第35行: | 第47行: | ||
end |
end |
||
function |
function p.ExpandTemplate(title, args) |
||
return mw.getCurrentFrame():expandTemplate{ |
return mw.getCurrentFrame():expandTemplate{ |
||
title = title, |
title = title, |
||
| 第42行: | 第54行: | ||
end |
end |
||
| ⚫ | |||
function Self.getArg(input, index) |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
2025年9月7日 (日) 02:28的版本
local p = {}
function p.getArg(input, index)
if not index then index = 1 end
if type(input) == "string" then
return input
end
return input.args[index] or input:getParent().args[index]
end
function p.hasChinese(str)
return type(str) == 'string' and string.match(str, "[\228-\233][\128-\191][\128-\191]") ~= nil
end
function p.LazyLoad(moduleName, toLowerCase)
toLowerCase = toLowerCase or false
local loaded = nil
local function doLoad()
if loaded == nil then
loaded = mw.loadData(moduleName)
if toLowerCase then
local lowerCaseLoaded = {}
for key, value in pairs(loaded) do
lowerCaseLoaded[string.lower(key)] = value
end
loaded = lowerCaseLoaded
end
end
return loaded
end
local meta = {}
meta.__index = function(_table, key)
return doLoad()[key]
end
meta.__pairs = function(_table)
return pairs(doLoad())
end
meta.__ipairs = function(_table)
return ipairs(doLoad())
end
local ret = {}
setmetatable(ret, meta)
return ret
end
function p.ExpandTemplate(title, args)
return mw.getCurrentFrame():expandTemplate{
title = title,
args = args
}
end
return p