diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-19 00:08:33 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-28 17:28:40 -0300 |
| commit | 447e8aa089fc189fef8434facfea2b0d84047749 (patch) | |
| tree | ecc68539c43cf2414f17da6acdf260a37d666300 /src | |
| parent | d90c3c918a2555eff8776e1acabab7a777f13c31 (diff) | |
| download | luarocks-447e8aa089fc189fef8434facfea2b0d84047749.tar.gz luarocks-447e8aa089fc189fef8434facfea2b0d84047749.tar.bz2 luarocks-447e8aa089fc189fef8434facfea2b0d84047749.zip | |
core.util: move type_check.merge_under to core.util.deep_merge_under
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/core/util.lua | 22 | ||||
| -rw-r--r-- | src/luarocks/type_check.lua | 15 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 10 |
3 files changed, 27 insertions, 20 deletions
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 3582cb54..daec9d05 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
| @@ -54,7 +54,7 @@ function util.show_table(t, tname, top_indent) | |||
| 54 | 54 | ||
| 55 | local function is_empty_table(tbl) return next(tbl) == nil end | 55 | local function is_empty_table(tbl) return next(tbl) == nil end |
| 56 | 56 | ||
| 57 | local function basic_serialize (o) | 57 | local function basic_serialize(o) |
| 58 | local so = tostring(o) | 58 | local so = tostring(o) |
| 59 | if type(o) == "function" then | 59 | if type(o) == "function" then |
| 60 | local info = debug.getinfo(o, "S") | 60 | local info = debug.getinfo(o, "S") |
| @@ -72,7 +72,7 @@ function util.show_table(t, tname, top_indent) | |||
| 72 | end | 72 | end |
| 73 | end | 73 | end |
| 74 | 74 | ||
| 75 | local function add_to_cart (value, name, indent, saved, field) | 75 | local function add_to_cart(value, name, indent, saved, field) |
| 76 | indent = indent or "" | 76 | indent = indent or "" |
| 77 | saved = saved or {} | 77 | saved = saved or {} |
| 78 | field = field or name | 78 | field = field or name |
| @@ -133,6 +133,24 @@ function util.deep_merge(dst, src) | |||
| 133 | end | 133 | end |
| 134 | end | 134 | end |
| 135 | 135 | ||
| 136 | --- Merges contents of src below those of dst's contents. | ||
| 137 | -- @param dst Destination table, which will receive src's contents. | ||
| 138 | -- @param src Table which provides new contents to dst. | ||
| 139 | function util.deep_merge_under(dst, src) | ||
| 140 | for k, v in pairs(src) do | ||
| 141 | if type(v) == "table" then | ||
| 142 | if not dst[k] then | ||
| 143 | dst[k] = {} | ||
| 144 | end | ||
| 145 | if type(dst[k]) == "table" then | ||
| 146 | util.deep_merge_under(dst[k], v) | ||
| 147 | end | ||
| 148 | elseif dst[k] == nil then | ||
| 149 | dst[k] = v | ||
| 150 | end | ||
| 151 | end | ||
| 152 | end | ||
| 153 | |||
| 136 | --- Clean up a path-style string ($PATH, $LUA_PATH/package.path, etc.), | 154 | --- Clean up a path-style string ($PATH, $LUA_PATH/package.path, etc.), |
| 137 | -- removing repeated entries and making sure only the relevant | 155 | -- removing repeated entries and making sure only the relevant |
| 138 | -- Lua version is used. | 156 | -- Lua version is used. |
diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 827c64b6..b204f5ee 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua | |||
| @@ -4,7 +4,6 @@ local type_check = {} | |||
| 4 | local cfg = require("luarocks.core.cfg") | 4 | local cfg = require("luarocks.core.cfg") |
| 5 | local vers = require("luarocks.core.vers") | 5 | local vers = require("luarocks.core.vers") |
| 6 | local util = require("luarocks.util") | 6 | local util = require("luarocks.util") |
| 7 | local require = nil | ||
| 8 | -------------------------------------------------------------------------------- | 7 | -------------------------------------------------------------------------------- |
| 9 | 8 | ||
| 10 | type_check.MAGIC_PLATFORMS = {} | 9 | type_check.MAGIC_PLATFORMS = {} |
| @@ -34,18 +33,6 @@ do | |||
| 34 | end | 33 | end |
| 35 | end | 34 | end |
| 36 | 35 | ||
| 37 | local function merge_under(dst, src) | ||
| 38 | for k, v in pairs(src) do | ||
| 39 | if dst[k] == nil then | ||
| 40 | if type(dst[k]) == "table" then | ||
| 41 | util.deep_merge(dst[k], v) | ||
| 42 | else | ||
| 43 | dst[k] = v | ||
| 44 | end | ||
| 45 | end | ||
| 46 | end | ||
| 47 | end | ||
| 48 | |||
| 49 | -- Build a table of schemas. | 36 | -- Build a table of schemas. |
| 50 | -- @param versions a table where each key is a version number as a string, | 37 | -- @param versions a table where each key is a version number as a string, |
| 51 | -- and the value is a schema specification. Schema versions are considered | 38 | -- and the value is a schema specification. Schema versions are considered |
| @@ -75,7 +62,7 @@ do | |||
| 75 | -- so that error messages can inform users when they try | 62 | -- so that error messages can inform users when they try |
| 76 | -- to use new features without bumping rockspec_format in their rockspecs. | 63 | -- to use new features without bumping rockspec_format in their rockspecs. |
| 77 | for i = #version_list, 2, -1 do | 64 | for i = #version_list, 2, -1 do |
| 78 | merge_under(schemas[version_list[i - 1]], schemas[version_list[i]]) | 65 | util.deep_merge_under(schemas[version_list[i - 1]], schemas[version_list[i]]) |
| 79 | end | 66 | end |
| 80 | 67 | ||
| 81 | return schemas | 68 | return schemas |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index f5506f53..ee4a803a 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -8,14 +8,16 @@ local util = {} | |||
| 8 | 8 | ||
| 9 | local core = require("luarocks.core.util") | 9 | local core = require("luarocks.core.util") |
| 10 | 10 | ||
| 11 | util.popen_read = core.popen_read | ||
| 12 | util.cleanup_path = core.cleanup_path | 11 | util.cleanup_path = core.cleanup_path |
| 13 | util.split_string = core.split_string | 12 | util.split_string = core.split_string |
| 14 | util.keys = core.keys | ||
| 15 | util.printerr = core.printerr | ||
| 16 | util.sortedpairs = core.sortedpairs | 13 | util.sortedpairs = core.sortedpairs |
| 17 | util.warning = core.warning | ||
| 18 | util.deep_merge = core.deep_merge | 14 | util.deep_merge = core.deep_merge |
| 15 | util.deep_merge_under = core.deep_merge_under | ||
| 16 | util.popen_read = core.popen_read | ||
| 17 | util.show_table = core.show_table | ||
| 18 | util.printerr = core.printerr | ||
| 19 | util.warning = core.warning | ||
| 20 | util.keys = core.keys | ||
| 19 | 21 | ||
| 20 | local unpack = unpack or table.unpack | 22 | local unpack = unpack or table.unpack |
| 21 | 23 | ||
