diff util/human/io.lua @ 14221:565debd9c37a

Merge 13.0->trunk
author Matthew Wild <mwild1@gmail.com>
date Fri, 12 Jun 2026 13:05:10 +0100
parents 7008869fcce2 7eb0e47418ab
children
line wrap: on
line diff
--- a/util/human/io.lua	Sun Jun 07 20:32:55 2026 +0200
+++ b/util/human/io.lua	Fri Jun 12 13:05:10 2026 +0100
@@ -235,6 +235,29 @@
 	return tonumber(n) * ( multipliers_lax[m] or 1 );
 end
 
+-- Compares simple version strings (numeric only, not semver compatible)
+-- (can be passed to table.sort)
+local function simple_version_compare(a, b)
+	local a_f, a_s, a_part = a:gmatch("%d+");
+	local b_f, b_s, b_part = b:gmatch("%d+");
+
+	a_part = a_f(a_s, a_part);
+	b_part = b_f(b_s, b_part);
+
+	while a_part and b_part do
+		local an, bn = tonumber(a_part), tonumber(b_part);
+		if an ~= bn then
+			return an < bn;
+		end
+		a_part = a_f(a_s, a_part);
+		b_part = b_f(b_s, b_part);
+	end
+
+	-- return true (a is lower) if b is exhausted
+	-- otherwise, they are equal or b is longer/greater (-> return false)
+	return b_part ~= nil;
+end
+
 return {
 	getchar = getchar;
 	getline = getline;
@@ -250,4 +273,5 @@
 	table = new_table;
 	parse_duration = parse_duration;
 	parse_duration_lax = parse_duration_lax;
+	simple_version_compare = simple_version_compare;
 };