Diff

util/startup.lua @ 12781:22066b02887f

util.startup: Provide a common Lua 5.3+ math.type() for Lua 5.2 Code deduplication
author Kim Alvefur <zash@zash.se>
date Wed, 19 Oct 2022 16:25:05 +0200
parent 12779:f0474d40364c
child 12782:8815d3090928
line wrap: on
line diff
--- a/util/startup.lua	Thu Oct 20 16:56:45 2022 +0200
+++ b/util/startup.lua	Wed Oct 19 16:25:05 2022 +0200
@@ -277,6 +277,20 @@
 	startup.detect_platform();
 	startup.detect_installed();
 	_G.prosody = prosody;
+
+	-- COMPAT Lua < 5.3
+	if not math.type then
+		-- luacheck: ignore 122/math
+		function math.type(n)
+			if type(n) == "number" then
+				if n % 1 == 0 and (n + 1 ~= n and n - 1 ~= n) then
+					return "integer"
+				else
+					return "float"
+				end
+			end
+		end
+	end
 end
 
 function startup.setup_datadir()