aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-22 21:10:59 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:49:17 +0300
commit0a1fd0aafb84212067c2a6454bad4aa5f3a154a9 (patch)
tree8027c00beacd34a57d8e01fa73e62c8ad995f21c
parent0e6068b309a4bb084322ed2934b8191d33f50626 (diff)
downloadluarocks-0a1fd0aafb84212067c2a6454bad4aa5f3a154a9.tar.gz
luarocks-0a1fd0aafb84212067c2a6454bad4aa5f3a154a9.tar.bz2
luarocks-0a1fd0aafb84212067c2a6454bad4aa5f3a154a9.zip
actually add the new changes
-rw-r--r--src/luarocks/core/util.lua58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua
index 6011e51e..b815a028 100644
--- a/src/luarocks/core/util.lua
+++ b/src/luarocks/core/util.lua
@@ -1,5 +1,9 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local debug = _tl_compat and _tl_compat.debug or debug; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local os = _tl_compat and _tl_compat.os or os; local package = _tl_compat and _tl_compat.package or package; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table 1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local debug = _tl_compat and _tl_compat.debug or debug; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local os = _tl_compat and _tl_compat.os or os; local package = _tl_compat and _tl_compat.package or package; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table
2local util = {} 2local util = {Ordering = {}, }
3
4
5
6
3 7
4 8
5 9
@@ -16,6 +20,7 @@ local dir_sep = package.config:sub(1, 1)
16 20
17 21
18 22
23
19function util.popen_read(cmd, spec) 24function util.popen_read(cmd, spec)
20 local tmpfile = (dir_sep == "\\") and 25 local tmpfile = (dir_sep == "\\") and
21 (os.getenv("TMP") .. "/luarocks-" .. tostring(math.floor(math.random() * 10000))) or 26 (os.getenv("TMP") .. "/luarocks-" .. tostring(math.floor(math.random() * 10000))) or
@@ -187,7 +192,7 @@ function util.split_string(str, delim, maxNb)
187 for part, pos in string.gmatch(str, pat) do 192 for part, pos in string.gmatch(str, pat) do
188 nb = nb + 1 193 nb = nb + 1
189 result[nb] = part 194 result[nb] = part
190 lastPos = tonumber(pos) 195 lastPos = math.tointeger(pos)
191 if nb == maxNb then break end 196 if nb == maxNb then break end
192 end 197 end
193 198
@@ -288,51 +293,46 @@ end
288 293
289 294
290 295
291function util.sortedpairs(tbl, sort_function) 296function util.sortedpairs(tbl, sort_by)
292 if not sort_function then
293 sort_function = default_sort
294 end
295 local keys = util.keys(tbl) 297 local keys = util.keys(tbl)
296 local sub_orders = {} 298 local sub_orders = nil
297 299
298 if type(sort_function) == "function" then 300 if sort_by == nil then
299 table.sort(keys, sort_function) 301 table.sort(keys, default_sort)
302 elseif type(sort_by) == "function" then
303 table.sort(keys, sort_by)
300 else 304 else
301 local order = sort_function
302 local ordered_keys = {}
303 local all_keys = keys
304 keys = {}
305 305
306 for _, order_entry in ipairs(order) do
307 local key, sub_order
308 306
309 if not (type(order_entry) == "table") then 307 sub_orders = sort_by.sub_orders
310 key = order_entry 308
311 else 309 local seen_ordered_key = {}
312 key = order_entry[1]
313 sub_order = order_entry[2]
314 end
315 310
311 local my_ordered_keys = {}
312
313 for _, key in ipairs(sort_by) do
316 if tbl[key] then 314 if tbl[key] then
317 ordered_keys[key] = true 315 seen_ordered_key[key] = true
318 sub_orders[key] = sub_order 316 table.insert(my_ordered_keys, key)
319 table.insert(keys, key)
320 end 317 end
321 end 318 end
322 319
323 table.sort(all_keys, default_sort) 320 table.sort(keys, default_sort)
324 for _, key in ipairs(all_keys) do 321
325 if not ordered_keys[key] then 322 for _, key in ipairs(keys) do
326 table.insert(keys, key) 323 if not seen_ordered_key[key] then
324 table.insert(my_ordered_keys, key)
327 end 325 end
328 end 326 end
327
328 keys = my_ordered_keys
329 end 329 end
330 330
331 local i = 1 331 local i = 1
332 return function() 332 return function()
333 local key = keys[i] 333 local key = keys[i]
334 i = i + 1 334 i = i + 1
335 return key, tbl[key], sub_orders[key] 335 return key, tbl[key], sub_orders and sub_orders[key]
336 end 336 end
337end 337end
338 338