Module:CommonData

-- CommonData

function VarSet(frame, name, value) local var = require('Module:Variables') --local n = tonumber( var.get('mynumber',0) ) or 100 var.define(name, value and tostring(value) or "") end

-- get one value from a row matching the querry local function GetSingleValueByName(frame) local args = frame.args local p1,p2,p3,p4 = args[1],args[2],args[3],args[4] local tableModule = require('Module:CommonData/' .. p1) local cols = tableModule.GetRawColumns(frame) local rows = tableModule.GetRawTable(frame) local colsR = {} for i,v in ipairs(cols) do       colsR[v] = i    end local key,keyColIndex,result = p3, colsR[p2], "" for _,v in pairs(rows) do       local value = tostring(v[keyColIndex]) if value == key then result = v[colsR[p4]]; break end end return result end

-- process wiki code per row matching the querry local function GetTranscludeEachRowByName(frame) local args = frame.args local p1,p2,p3,code,limit = args[1],args[2],args[3],args.wiki, tonumber(args.limit) or 500 local tableModule = require('Module:CommonData/' .. p1) local cols = tableModule.GetRawColumns(frame) local rows = tableModule.GetRawTable(frame) code = mw.text.unstripNoWiki(code)     -- go ahead and remove the nowiki

local colsR, colsCode = {}, {}         -- reverse cols and cols in code for i,v in ipairs(cols) do       colsR[v] = i        if code:find(v) and code:find("{{#var:"..v.."[}|]") then colsCode[#colsCode + 1] = i       end end local result,resulti,count = {}, 0, 0 local key,keyColIndex = p3, colsR[p2] for _,v in pairs(rows) do       local value = tostring(v[keyColIndex])

if value == key then for _,v2 in pairs(colsCode) do -- add cols value = v[v2] value = value and tostring(value) or "" resulti = resulti + 1 result[resulti] = '' end resulti = resulti + 1 result[resulti] = code count = count + 1 end if count > limit then break end end result = count > 0 and table.concat(result) or "" if result == "" then -- count > 0 can still be "" if user filters in code result = args.default and mw.text.unstripNoWiki(args.default) or "" end return result ~= "" and frame:preprocess(result) or "" end

local p = {}

function p.vardefine(frame) VarSet(frame, 'mynumber', frame.args[1]) end

function p.GetRowValue(frame) return GetSingleValueByName(frame) end

function p.GetRowsTransclude(frame) return GetTranscludeEachRowByName(frame) end

return p