Software /
code /
prosody
Comparison
util/format.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 | 12590:5eaf77114fdb |
child | 12975:d10957394a3c |
comparison
equal
deleted
inserted
replaced
12780:2c0c1b18a02b | 12781:22066b02887f |
---|---|
9 local unpack = table.unpack; | 9 local unpack = table.unpack; |
10 local pack = table.pack; | 10 local pack = table.pack; |
11 local valid_utf8 = require "util.encodings".utf8.valid; | 11 local valid_utf8 = require "util.encodings".utf8.valid; |
12 local type = type; | 12 local type = type; |
13 local dump = require "util.serialization".new("debug"); | 13 local dump = require "util.serialization".new("debug"); |
14 local num_type = math.type or function (n) | 14 local num_type = math.type; |
15 return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; | |
16 end | |
17 | 15 |
18 -- In Lua 5.3+ these formats throw an error if given a float | 16 -- In Lua 5.3+ these formats throw an error if given a float |
19 local expects_integer = { c = true, d = true, i = true, o = true, u = true, X = true, x = true, }; | 17 local expects_integer = { c = true, d = true, i = true, o = true, u = true, X = true, x = true, }; |
20 -- In Lua 5.2 these throw an error given a negative number | 18 -- In Lua 5.2 these throw an error given a negative number |
21 local expects_positive = { o = true; u = true; x = true; X = true }; | 19 local expects_positive = { o = true; u = true; x = true; X = true }; |