diff options
-rw-r--r-- | src/luarocks/persist.lua | 10 |
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. |
6 | module("luarocks.persist", package.seeall) | 6 | module("luarocks.persist", package.seeall) |
7 | 7 | ||
8 | local 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 |
27 | end | 29 | end |
28 | 30 | ||
31 | local function string_sort(a,b) | ||
32 | return tostring(a) < tostring(b) | ||
33 | end | ||
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") |