模块:Utils:修订间差异
来自星露谷物语扩展百科
更多操作
创建页面 |
getArg |
||
| 第40行: | 第40行: | ||
args = args | args = args | ||
} | } | ||
end | |||
function Self.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 | end | ||
return Self | return Self | ||
2025年9月7日 (日) 02:21的版本
local Self = {}
function Self.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 Self.ExpandTemplate(title, args)
return mw.getCurrentFrame():expandTemplate{
title = title,
args = args
}
end
function Self.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
return Self