author | unknown <Maria@abbate-95206d9a.(none)> | 2013年06月20日 18:01:44 +0200 |
---|---|---|
committer | unknown <Maria@abbate-95206d9a.(none)> | 2013年06月20日 18:01:44 +0200 |
commit | 2fe7279768fa30e0afdbd2d4c17c958c9ece62b3 (patch) | |
tree | 8a0123861a3e5927a6030e79dcc858696e0845ef | |
parent | 84cd0a601bd81fe166cc2a4560bcd5cb45908b8e (diff) | |
download | gsl-shell-2fe7279768fa30e0afdbd2d4c17c958c9ece62b3.tar.gz |
-rw-r--r-- | gdt-parse-csv.lua | 9 |
diff --git a/gdt-parse-csv.lua b/gdt-parse-csv.lua index 631371da..6c71288b 100644 --- a/gdt-parse-csv.lua +++ b/gdt-parse-csv.lua @@ -140,9 +140,9 @@ local function csv_format(x) end end -local function write_csv_row(f, row) +local function write_csv_row(f, row, nc) local rf = {} - for i = 1, #row do + for i = 1, nc do rf[i] = csv_format(row[i]) end f:write(string.format("%s\n", table.concat(rf, ","))) @@ -151,11 +151,12 @@ end function gdt.write_csv(t, filename) local f = assert(io.open(filename, "w")) local hs = t:headers() - write_csv_row(f, hs) + local nc = #hs + write_csv_row(f, hs, nc) for i, r in t:rows() do local s = {} for j, k in ipairs(hs) do s[j] = r[k] end - write_csv_row(f, s) + write_csv_row(f, s, nc) end f:close() end |