Software /
code /
prosody
Comparison
util/json.lua @ 6785:bf1f09a5bcf7
util.json: Remove use of newproxy
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 13 Mar 2015 21:11:33 +0100 |
parent | 5776:bd0ff8ae98a8 |
child | 7235:ee1f7e1e548c |
comparison
equal
deleted
inserted
replaced
6784:4da860edc27c | 6785:bf1f09a5bcf7 |
---|---|
11 local s_char = string.char; | 11 local s_char = string.char; |
12 local tostring, tonumber = tostring, tonumber; | 12 local tostring, tonumber = tostring, tonumber; |
13 local pairs, ipairs = pairs, ipairs; | 13 local pairs, ipairs = pairs, ipairs; |
14 local next = next; | 14 local next = next; |
15 local error = error; | 15 local error = error; |
16 local newproxy, getmetatable, setmetatable = newproxy, getmetatable, setmetatable; | 16 local getmetatable, setmetatable = getmetatable, setmetatable; |
17 local print = print; | 17 local print = print; |
18 | 18 |
19 local has_array, array = pcall(require, "util.array"); | 19 local has_array, array = pcall(require, "util.array"); |
20 local array_mt = has_array and getmetatable(array()) or {}; | 20 local array_mt = has_array and getmetatable(array()) or {}; |
21 | 21 |
22 --module("json") | 22 --module("json") |
23 local json = {}; | 23 local json = {}; |
24 | 24 |
25 local null = newproxy and newproxy(true) or {}; | 25 local null = setmetatable({}, { __tostring = function() return "null"; end; }); |
26 if getmetatable and getmetatable(null) then | |
27 getmetatable(null).__tostring = function() return "null"; end; | |
28 end | |
29 json.null = null; | 26 json.null = null; |
30 | 27 |
31 local escapes = { | 28 local escapes = { |
32 ["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", | 29 ["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", |
33 ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t"}; | 30 ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t"}; |