local p = {}
local format = string.format
local sub = string.sub
local match = string.match
local gmatch = string.gmatch
local insert = table.insert
local concat = table.concat
local pairs = pairs
local unstripNoWiki = mw.text.unstripNoWiki
local initNoWikiCount = mw.loadData('Module:Sandbox/Chi_ZJ2/var/init')[1]
local currNoWikiCount = 0
local function trim(str)
return match(str, '^ *(.-) *$')
end
local function explode(str, sep)
local result = {}
for mat in gmatch(str .. sep, '(.-)' .. sep) do
insert(result, mat)
end
return result
end
local function getNoWiki(from, to)
local markers = {}
for i = from, to do
insert(markers, '\127\'"`UNIQ--nowiki-' .. format('%08X', i) .. '-QINU`"\'\127')
end
local resultString = unstripNoWiki(concat(markers, '\127SPLIT\127'))
local results = explode(resultString, '\127SPLIT\127')
return results
end
local function getVar(frame, key)
local noWikiList = getNoWiki(initNoWikiCount, currNoWikiCount - 1)
for i = #noWikiList, 1, -1 do
local _, currKey, currVal = unpack(explode(noWikiList[i], '\'"`'))
if currKey == key then
return currVal
end
end
end
function p.main(frame)
currNoWikiCount = tonumber(sub(frame.args[1], 18, -10), 16)
local args = frame:getParent().args
return getVar(frame, trim(args[2]))
end
function p.init(frame)
return ''
end
return p