Skip to content

Commit

Permalink
sip-registers.lua: sort keys for printing
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jun 9, 2024
1 parent c5c47a4 commit 44aa32b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions sip-registers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ do
indent = indent or ' '
io.write("{\n")
local l = 0
local t = 0
for k, v in pairs(tbl) do
if l == 1 then
io.write(",\n")
end
local n = 0
local skeys = {}
for k in pairs(tbl) do
table.insert(skeys, k)
n = n + 1
end
table.sort(skeys)
for _, k in pairs(skeys) do
v = tbl[k]
io.write(indent .. string.format("%q", k) .. ": ")
if type(v) == "table" then
print_j(v, indent .. ' ')
io.write("\n")
t = 1
else
if type(v) == "number" then
io.write(tostring(v))
Expand All @@ -73,10 +75,12 @@ do
end
t = 0
end
l = 1
end
if t == 0 then
io.write("\n")
l = l + 1
if l == n then
io.write("\n")
else
io.write(",\n")
end
end
io.write(string.sub(indent, 1, -5) .. "}")
end
Expand Down

0 comments on commit 44aa32b

Please sign in to comment.