aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--teal-src/util/datamapper.tl2
-rw-r--r--teal-src/util/jsonschema.tl2
-rw-r--r--teal-src/util/mathcompat.tl15
-rw-r--r--util/datamapper.lua4
-rw-r--r--util/mathcompat.lua13
-rw-r--r--util/serialization.lua4
-rw-r--r--util/startup.lua11
7 files changed, 41 insertions, 10 deletions
diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl
index 23f5ecaa..4ff3a02c 100644
--- a/teal-src/util/datamapper.tl
+++ b/teal-src/util/datamapper.tl
@@ -19,6 +19,8 @@
-- TODO s/number/integer/ once we have appropriate math.type() compat
--
+if not math.type then require "util.mathcompat" end
+
local st = require "util.stanza";
local json = require"util.json"
local pointer = require"util.jsonpointer";
diff --git a/teal-src/util/jsonschema.tl b/teal-src/util/jsonschema.tl
index 160c164c..14b04370 100644
--- a/teal-src/util/jsonschema.tl
+++ b/teal-src/util/jsonschema.tl
@@ -8,6 +8,8 @@
-- https://json-schema.org/draft/2020-12/json-schema-validation.html
--
+if not math.type then require "util.mathcompat" end
+
local json = require"util.json"
local null = json.null;
diff --git a/teal-src/util/mathcompat.tl b/teal-src/util/mathcompat.tl
new file mode 100644
index 00000000..1e3f9bab
--- /dev/null
+++ b/teal-src/util/mathcompat.tl
@@ -0,0 +1,15 @@
+if not math.type then
+ local enum number_subtype
+ "float" "integer"
+ end
+ local function math_type(t:any) : number_subtype
+ if t is number then
+ if t % 1 == 0 and t ~= t+1 and t ~= t-1 then
+ return "integer"
+ else
+ return "float"
+ end
+ end
+ end
+ _G.math.type = math_type
+end
diff --git a/util/datamapper.lua b/util/datamapper.lua
index 2378314c..e1484525 100644
--- a/util/datamapper.lua
+++ b/util/datamapper.lua
@@ -1,5 +1,9 @@
-- This file is generated from teal-src/util/datamapper.lua
+if not math.type then
+ require("util.mathcompat")
+end
+
local st = require("util.stanza");
local pointer = require("util.jsonpointer");
diff --git a/util/mathcompat.lua b/util/mathcompat.lua
new file mode 100644
index 00000000..e8acb261
--- /dev/null
+++ b/util/mathcompat.lua
@@ -0,0 +1,13 @@
+if not math.type then
+
+ local function math_type(t)
+ if type(t) == "number" then
+ if t % 1 == 0 and t ~= t + 1 and t ~= t - 1 then
+ return "integer"
+ else
+ return "float"
+ end
+ end
+ end
+ _G.math.type = math_type
+end
diff --git a/util/serialization.lua b/util/serialization.lua
index 6552d53b..e2e104f1 100644
--- a/util/serialization.lua
+++ b/util/serialization.lua
@@ -21,6 +21,10 @@ local to_hex = require "util.hex".to;
local pcall = pcall;
local envload = require"util.envload".envload;
+if not math.type then
+ require "util.mathcompat"
+end
+
local pos_inf, neg_inf = math.huge, -math.huge;
local m_type = math.type;
diff --git a/util/startup.lua b/util/startup.lua
index 9e512cb3..68b74984 100644
--- a/util/startup.lua
+++ b/util/startup.lua
@@ -280,16 +280,7 @@ function startup.init_global_state()
-- 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
+ require "util.mathcompat"
end
end