FANDOM


function PrintTable(data, row_attr, cell_attr, cell_transformer)
    local output = ''
 
    local i = 1
    while true do
        local row = data[i]
        if row == nil then
            break
        end
 
        local row_attr_str = ''
        if type(row_attr) == 'string' then
            row_attr_str = row_attr
        elseif type(row_attr) == 'function' then
            row_attr_str = row_attr(i)
        end
 
        output = output .. '|- ' .. row_attr_str .. '\n'
 
        local j = 1 
        while row[j] ~= nil do
 
            local cell_attr_str = ''
            if type(cell_attr) == 'string' then
                cell_attr_str = cell_attr .. ' |'
            elseif type(cell_attr) == 'function' then
                cell_attr_str = cell_attr(i, j) .. ' |'
            end
 
            local cell = row[j]
            if type(cell_transformer) == 'function' then
                cell = cell_transformer(row[j])
            end
            output = output .. '| ' .. cell_attr_str .. cell .. '\n'
 
            j = j + 1
        end
        i = i + 1
    end
    return output
end
 
return PrintTable
Community content is available under CC-BY-SA unless otherwise noted.