diff --git a/lua/pl/pretty.lua b/lua/pl/pretty.lua index a9abe0ea..fbf60a9b 100644 --- a/lua/pl/pretty.lua +++ b/lua/pl/pretty.lua @@ -248,7 +248,14 @@ function pretty.write (tbl,space,not_clever) used[i] = true end end - for key,val in pairs(t) do + local ordered_keys = {} + for k,v in pairs(t) do + if type(k) ~= 'number' then + ordered_keys[#ordered_keys + 1] = k + end + end + table.sort(ordered_keys) + local function write_entry (key, val) local tkey = type(key) local numkey = tkey == 'number' if not_clever then @@ -268,6 +275,16 @@ function pretty.write (tbl,space,not_clever) end end end + for i = 1, #ordered_keys do + local key = ordered_keys[i] + local val = t[key] + write_entry(key, val) + end + for key,val in pairs(t) do + if type(key) == 'number' then + write_entry(key, val) + end + end tables[t] = nil eat_last_comma() putln(oldindent..'},')