Module:ModuleLevelTable: Difference between revisions

From The First Descendant Wiki
No edit summary
No edit summary
Line 22: Line 22:
end
end


function p.getTable(input)
function p.getFirstElement(frame)
     local array = p.parseCSV(input.args[1] )
    local input = frame.args[1]
     local array = p.parseCSV(input)
     return array[1][1]
     return array[1][1]
end
end


return p
return p

Revision as of 03:22, 4 June 2024

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

local p = {}

function p.parseCSV(input)
    local array = {}
    local i = 1
    
    -- Split the input by lines
    for line in mw.text.split(input, "\n") do
        array[i] = {}
        local j = 1
        
        -- Split each line by commas
        for cell in mw.text.split(line, ",") do
            array[i][j] = mw.text.trim(cell)
            j = j + 1
        end
        
        i = i + 1
    end
    
    return array
end

function p.getFirstElement(frame)
    local input = frame.args[1]
    local array = p.parseCSV(input)
    return array[1][1]
end

return p