This commit is contained in:
Robin Wellner 2015-05-20 02:18:05 +02:00
commit c6d9904da7

View File

@ -1,4 +1,4 @@
local pairs, ipairs, tostring, type, concat, dump, floor = pairs, ipairs, tostring, type, table.concat, string.dump, math.floor local pairs, ipairs, tostring, type, concat, dump, floor, format = pairs, ipairs, tostring, type, table.concat, string.dump, math.floor, string.format
local function getchr(c) local function getchr(c)
return "\\" .. c:byte() return "\\" .. c:byte()
@ -11,9 +11,12 @@ end
local oddvals = {[tostring(1/0)] = '1/0', [tostring(-1/0)] = '-1/0', [tostring(0/0)] = '0/0'} local oddvals = {[tostring(1/0)] = '1/0', [tostring(-1/0)] = '-1/0', [tostring(0/0)] = '0/0'}
local function write(t, memo, rev_memo) local function write(t, memo, rev_memo)
local ty = type(t) local ty = type(t)
if ty == 'number' or ty == 'boolean' or ty == 'nil' then if ty == 'number' then
t = tostring(t) t = format("%.17g", t)
return oddvals[t] or t return oddvals[t] or t
elseif or ty == 'boolean' or ty == 'nil' then
t = tostring(t)
return tostring(t)
elseif ty == 'string' then elseif ty == 'string' then
return make_safe(t) return make_safe(t)
elseif ty == 'table' or ty == 'function' then elseif ty == 'table' or ty == 'function' then