From e64c5e30c2ab1f59c5051f2bd66f053d34a6eb25 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 19 Oct 2022 16:25:05 +0200 Subject: util.startup: Provide a common Lua 5.3+ math.type() for Lua 5.2 Code deduplication --- util/startup.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'util/startup.lua') diff --git a/util/startup.lua b/util/startup.lua index 10ff1875..9e512cb3 100644 --- a/util/startup.lua +++ b/util/startup.lua @@ -277,6 +277,20 @@ function startup.init_global_state() 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() -- cgit v1.2.3