From c5ba8a8301ec4d1c3c013388385e30369c1db8f5 Mon Sep 17 00:00:00 2001 From: jperon Date: Thu, 12 Nov 2020 20:38:11 +0100 Subject: [PATCH] Order keys in settings.reader.lua (#6868) * Order keys in settings.reader.lua * Comma at the end of last item in table. --- frontend/dump.lua | 17 ++++++++--------- frontend/luasettings.lua | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/frontend/dump.lua b/frontend/dump.lua index a2d26adb8..aa74e8704 100644 --- a/frontend/dump.lua +++ b/frontend/dump.lua @@ -6,7 +6,7 @@ local isUbuntuTouch = os.getenv("UBUNTU_APPLICATION_ISOLATION") ~= nil local insert = table.insert local indent_prefix = " " -local function _serialize(what, outt, indent, max_lv, history) +local function _serialize(what, outt, indent, max_lv, history, _pairs) if not max_lv then max_lv = math.huge end @@ -28,16 +28,14 @@ local function _serialize(what, outt, indent, max_lv, history) local new_history = { what, unpack(history) } local didrun = false insert(outt, "{") - for k, v in pairs(what) do - if didrun then - insert(outt, ",") - end + for k, v in _pairs(what) do insert(outt, "\n") insert(outt, string.rep(indent_prefix, indent+1)) insert(outt, "[") - _serialize(k, outt, indent+1, max_lv, new_history) + _serialize(k, outt, indent+1, max_lv, new_history, _pairs) insert(outt, "] = ") - _serialize(v, outt, indent+1, max_lv, new_history) + _serialize(v, outt, indent+1, max_lv, new_history, _pairs) + insert(outt, ",") didrun = true end if didrun then @@ -73,9 +71,10 @@ You can optionally specify a maximum recursion depth in `max_lv`. @param data the object you want serialized (table, string, number, boolean, nil) @param max_lv optional maximum recursion depth --]] -local function dump(data, max_lv) +local function dump(data, max_lv, ordered) local out = {} - _serialize(data, out, 0, max_lv) + local _pairs = ordered and require("ffi/util").orderedPairs or pairs + _serialize(data, out, 0, max_lv, nil, _pairs) return table.concat(out) end diff --git a/frontend/luasettings.lua b/frontend/luasettings.lua index de5862f06..5ad5c68dd 100644 --- a/frontend/luasettings.lua +++ b/frontend/luasettings.lua @@ -198,7 +198,7 @@ function LuaSettings:flush() if f_out ~= nil then os.setlocale('C', 'numeric') f_out:write("-- we can read Lua syntax here!\nreturn ") - f_out:write(dump(self.data)) + f_out:write(dump(self.data, nil, true)) f_out:write("\n") ffiutil.fsyncOpenedFile(f_out) -- force flush to the storage device f_out:close()