Software /
code /
prosody
Comparison
util/jsonpointer.lua @ 12499:03e307952816 0.12
util.jsonpointer: Fix Lua <5.3 compat
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 09 May 2022 22:36:57 +0200 |
parent | 12496:87c3d45208ef |
child | 12781:22066b02887f |
comparison
equal
deleted
inserted
replaced
12496:87c3d45208ef | 12499:03e307952816 |
---|---|
1 local m_type = math.type or function (n) | |
2 return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; | |
3 end; | |
4 | |
1 local function unescape_token(escaped_token) | 5 local function unescape_token(escaped_token) |
2 local unescaped = escaped_token:gsub("~1", "/"):gsub("~0", "~") | 6 local unescaped = escaped_token:gsub("~1", "/"):gsub("~0", "~") |
3 return unescaped | 7 return unescaped |
4 end | 8 end |
5 | 9 |
13 local idx = next(ref) | 17 local idx = next(ref) |
14 local new_ref | 18 local new_ref |
15 | 19 |
16 if type(idx) == "string" then | 20 if type(idx) == "string" then |
17 new_ref = ref[token] | 21 new_ref = ref[token] |
18 elseif math.type(idx) == "integer" then | 22 elseif m_type(idx) == "integer" then |
19 local i = tonumber(token) | 23 local i = tonumber(token) |
20 if token == "-" then | 24 if token == "-" then |
21 i = #ref + 1 | 25 i = #ref + 1 |
22 end | 26 end |
23 new_ref = ref[i + 1] | 27 new_ref = ref[i + 1] |