Module:ListRefOfID

Documentation for this module may be created at Module:ListRefOfID/doc

local getArgs = require('Module:Arguments').getArgs;
local defArgs = require('Module:Arguments').defaultArgs;
local listRefOfID = {};

function listRefOfID.func1( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];

  local text = "";
  function split(str, delim)
   local result = {}
    local pat = "(.-)" .. delim .. "()"
    local lastPos
    for part, pos in string.gfind(str, pat) do
        table.insert(result, part)
        lastPos = pos
    end
    table.insert(result, string.sub(str, lastPos))
    return result
  end
  local bucket = {}
  for title,sp,id in arg:gmatch("&&([^&]+)&&([^&]+)&&([^\n]+)") do
    if (bucket[title] == nil) then
      local t = split(title, ",")
      bucket[title] = t[3] .. t[2]
    end
  end
  for k,v in pairs(bucket) do
    text = text .. "\n&-\n& " .. string.sub(v,0,4) .. " && " .. string.sub(v,5) .. " && [[{{#get:2|Reference}}:" .. k .."&" .. string.gsub(k, ",", ", ") .. "]]"
  end

  return frame:preprocess(text);
end

return listRefOfID;