]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
table_print: sort numbers by their value instead of lexicographic representation
authorPetr Špaček <petr.spacek@nic.cz>
Fri, 10 Jul 2020 20:09:46 +0000 (22:09 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 2 Nov 2020 09:26:44 +0000 (10:26 +0100)
Side-effect is that keys are grouped by their type, so numbers come
first and strings later..

daemon/lua/sandbox.lua.in

index ec33f2622b2d5d7f967f33cd7baeea8730c380b5..dfbf815be7cdb174036dea73b2a6ba76fa18d228 100644 (file)
@@ -511,7 +511,7 @@ local function funcsign(f)
        return "(" .. table.concat(func_args, ", ") .. ")"
 end
 
-function table_print (tt, indent, done)
+function table_print(tt, indent, done)
        done = done or {}
        indent = indent or 0
        local result = ""
@@ -521,7 +521,17 @@ function table_print (tt, indent, done)
                for k in pairs(unordered_tt) do
                        table.insert(keys, k)
                end
-               table.sort(keys, function (a, b) return tostring(a) < tostring(b) end)
+               table.sort(keys,
+                       function (a, b)
+                               if type(a) ~= type(b) then
+                                       return type(a) < type(b)
+                               end
+                               if type(a) == 'number' then
+                                       return a < b
+                               else
+                                       return tostring(a) < tostring(b)
+                               end
+                       end)
                local i = 0
                return function()
                        i = i + 1