FANDOM


local p = {}
 
    --From: http://forums.wowace.com/showpost.php?p=304611&postcount=2
    function p.sortTable(unsortedTable)
        local sortedTable = {}
 
        for k in pairs(unsortedTable) do
        	sortedTable[ #sortedTable +1 ] = k
        end
        table.sort(sortedTable)
 
        --for i = 1, #sortedTable do
        	--print(sortedTable[i], unsortedTable[sortedTable[i]] )
        --end
        return sortedTable
    end
 
    --From: http://stackoverflow.com/a/4934441
    function p.printTable(t)
        function printTableHelper(t, spacing)
            for k,v in pairs(t) do
                mw.log(spacing..tostring(k), v)
                if (type(v) == "table") then 
                    printTableHelper(v, spacing.."\t")
                end
            end
        end
 
        printTableHelper(t, "");
    end
 
    function p.splitParameters(tbl)
        local params = {}
        local groups = {}
        local sorted = p.sortTable(tbl)
        for i = 1, #sorted do
            for x,y in string.gmatch(sorted[i],'(%a+)(%d+)') do
                if groups[x] == nil then
                    groups[x] = {}
                end
                table.insert(groups[x],tbl[sorted[i]])
            end
        end
 
        return groups
    end
 
    function p.keyList(tbl)
        local keys = {}
 
        for i,v in pairs(tbl) do
            table.insert(keys,i)
        end
 
        return keys
    end
 
    function p.valueList(tbl)
        local values = {}
 
        for i,v in pairs(tbl) do
            table.insert(values,v)
        end
 
        return values
    end
 
    function p.tblLen(tbl)
        return #p.keyList(tbl)
    end
 
    function p.findWhere(tbl, obj)
        local keys = p.keyList(obj)
        local values = p.valueList(obj)
 
        if #keys == #values then
            for m=1, #keys do
                for n=1, p.tblLen(tbl) do
                    local search_val = values[m] or ""
                    local search_key = keys[m] or ""
                    local tbl_val = tbl[n][search_key] or ""
                    if tbl_val == search_val then
                        return tbl[n]
                    end
                end
            end
        end
 
    end
 
    function p.inTable(tbl,val)
        for i,v in pairs(tbl) do
            if v == val then
                return true
            end
        end   
    end
 
    function p.getJSON(page)
        local pageData = mw.title.new(page)
        local content = ""
        local parsedJSON = {}
 
        if pageData.exists then
            content = pageData:getContent()  
            pageData.exists = json.decode(pcontents)
        end
 
        return pageData.exists
    end
 
    function p.allDefined(frame)
        local tArgs = frame:getParent().args
        local validate = 0
 
        for i,v in pairs(tArgs) do
            if v == '' then
                validate = validate +1
            end
        end
        if validate == 0 then
            return true
        end
    end
 
return p
Nutzung von Community-Inhalten gemäß CC-BY-SA , sofern nicht anders angegeben.