Comparison

util/human/io.lua @ 11892:e712133b4de1

util.human.io: Pass nil to cell mapper to signal missing value Seems more like conventional Lua than passing an empty string to signal lack of value.
author Kim Alvefur <zash@zash.se>
date Fri, 12 Nov 2021 11:43:24 +0100
parent 10917:1eb83bc6f706
child 11893:afef1e170de7
comparison
equal deleted inserted replaced
11891:6a241e66eec5 11892:e712133b4de1
129 titles, row = true, array.pluck(col_specs, "title", ""); 129 titles, row = true, array.pluck(col_specs, "title", "");
130 end 130 end
131 local output = {}; 131 local output = {};
132 for i, column in ipairs(col_specs) do 132 for i, column in ipairs(col_specs) do
133 local width = widths[i]; 133 local width = widths[i];
134 local v = (not titles and column.mapper or tostring)(row[not titles and column.key or i] or "", row); 134 local v = row[not titles and column.key or i];
135 if not titles and column.mapper then
136 v = column.mapper(v, row);
137 end
138 if v == nil then
139 v = "";
140 else
141 v = tostring(v);
142 end
135 if #v < width then 143 if #v < width then
136 if column.align == "right" then 144 if column.align == "right" then
137 v = padleft(v, width); 145 v = padleft(v, width);
138 else 146 else
139 v = padright(v, width); 147 v = padright(v, width);