mirror of
https://github.com/gvx/Ser.git
synced 2024-11-26 01:44:22 +00:00
Merge branch 'master' of https://github.com/gvx/Ser
This commit is contained in:
commit
c6d9904da7
9
ser.lua
9
ser.lua
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user