From 1e4eb39820b4ab4c6591e531686f347886c1f2d8 Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 18 Apr 2014 13:01:36 +0100 Subject: [PATCH] Added lovebird.compare() for improved sorting in env browser --- lovebird.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lovebird.lua b/lovebird.lua index 81f7d6d..2237bbb 100644 --- a/lovebird.lua +++ b/lovebird.lua @@ -346,7 +346,7 @@ lovebird.pages["env.json"] = [[ table.insert(keys, k) end end - table.sort(keys, function(a, b) return tostring(a) < tostring(b) end) + table.sort(keys, lovebird.compare) for _, k in pairs(keys) do local v = t[k] ?> @@ -447,6 +447,18 @@ function lovebird.truncate(str, len) end +function lovebird.compare(a, b) + local na, nb = tonumber(a), tonumber(b) + if na then + if nb then return na < nb end + return false + elseif nb then + return true + end + return tostring(a) < tostring(b) +end + + function lovebird.checkwhitelist(addr) if lovebird.whitelist == nil then return true end for _, a in pairs(lovebird.whitelist) do