mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Order keys in settings.reader.lua (#6868)
* Order keys in settings.reader.lua * Comma at the end of last item in table.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user