From a90a0d3ec2783df75343d366d4b52e586b42f6e6 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 5 Dec 2010 13:57:46 -0200 Subject: Make sorting for manifest table stable. --- src/luarocks/persist.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 70a89b8d..d74a805e 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua @@ -5,6 +5,8 @@ -- as it is used in the bootstrapping stage of the cfg module. module("luarocks.persist", package.seeall) +local util = require("luarocks.util") + --- Load a Lua file containing assignments, storing them in a table. -- The global environment is not propagated to the loaded file. -- @param filename string: the name of the file. @@ -26,6 +28,10 @@ function load_into_table(filename, tbl) return result end +local function string_sort(a,b) + return tostring(a) < tostring(b) +end + --- Write a table as Lua code representing a table to disk -- (that is, in curly brackets notation). -- This function handles only numbers, strings and tables @@ -37,7 +43,7 @@ local function write_table(out, tbl, level) local sep = "\n" local indent = true local i = 1 - for k, v in pairs(tbl) do + for k, v in util.sortedpairs(tbl, string_sort) do out:write(sep) if indent then for n = 1,level do out:write(" ") end @@ -89,7 +95,7 @@ function save_from_table(filename, tbl) if not out then return nil, "Cannot create file at "..filename end - for k, v in pairs(tbl) do + for k, v in util.sortedpairs(tbl, string_sort) do out:write(k.." = ") write_table(out, v, 1) out:write("\n") -- cgit v1.2.3-55-g6feb