aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-12-05 13:57:46 -0200
committerHisham Muhammad <hisham@gobolinux.org>2010-12-05 13:57:46 -0200
commita90a0d3ec2783df75343d366d4b52e586b42f6e6 (patch)
tree8a4916ab31580d6e5e7e2d842a52346064b4c5f9
parentb113a72b63d494828bb6b28833cc53de21b02aeb (diff)
downloadluarocks-a90a0d3ec2783df75343d366d4b52e586b42f6e6.tar.gz
luarocks-a90a0d3ec2783df75343d366d4b52e586b42f6e6.tar.bz2
luarocks-a90a0d3ec2783df75343d366d4b52e586b42f6e6.zip
Make sorting for manifest table stable.
-rw-r--r--src/luarocks/persist.lua10
1 files 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 @@
5-- as it is used in the bootstrapping stage of the cfg module. 5-- as it is used in the bootstrapping stage of the cfg module.
6module("luarocks.persist", package.seeall) 6module("luarocks.persist", package.seeall)
7 7
8local util = require("luarocks.util")
9
8--- Load a Lua file containing assignments, storing them in a table. 10--- Load a Lua file containing assignments, storing them in a table.
9-- The global environment is not propagated to the loaded file. 11-- The global environment is not propagated to the loaded file.
10-- @param filename string: the name of the file. 12-- @param filename string: the name of the file.
@@ -26,6 +28,10 @@ function load_into_table(filename, tbl)
26 return result 28 return result
27end 29end
28 30
31local function string_sort(a,b)
32 return tostring(a) < tostring(b)
33end
34
29--- Write a table as Lua code representing a table to disk 35--- Write a table as Lua code representing a table to disk
30-- (that is, in curly brackets notation). 36-- (that is, in curly brackets notation).
31-- This function handles only numbers, strings and tables 37-- This function handles only numbers, strings and tables
@@ -37,7 +43,7 @@ local function write_table(out, tbl, level)
37 local sep = "\n" 43 local sep = "\n"
38 local indent = true 44 local indent = true
39 local i = 1 45 local i = 1
40 for k, v in pairs(tbl) do 46 for k, v in util.sortedpairs(tbl, string_sort) do
41 out:write(sep) 47 out:write(sep)
42 if indent then 48 if indent then
43 for n = 1,level do out:write(" ") end 49 for n = 1,level do out:write(" ") end
@@ -89,7 +95,7 @@ function save_from_table(filename, tbl)
89 if not out then 95 if not out then
90 return nil, "Cannot create file at "..filename 96 return nil, "Cannot create file at "..filename
91 end 97 end
92 for k, v in pairs(tbl) do 98 for k, v in util.sortedpairs(tbl, string_sort) do
93 out:write(k.." = ") 99 out:write(k.." = ")
94 write_table(out, v, 1) 100 write_table(out, v, 1)
95 out:write("\n") 101 out:write("\n")