Mercurial > wow > askmrrobot
comparison Libs/AceSerializer-3.0/AceSerializer-3.0.lua @ 106:e635cd648e01 v49
7.2 update
author | yellowfive |
---|---|
date | Tue, 28 Mar 2017 16:10:00 -0700 |
parents | 01b63b8ed811 |
children |
comparison
equal
deleted
inserted
replaced
105:3ce266c86bd3 | 106:e635cd648e01 |
---|---|
8 -- and can be accessed directly, without having to explicitly call AceSerializer itself.\\ | 8 -- and can be accessed directly, without having to explicitly call AceSerializer itself.\\ |
9 -- It is recommended to embed AceSerializer, otherwise you'll have to specify a custom `self` on all calls you | 9 -- It is recommended to embed AceSerializer, otherwise you'll have to specify a custom `self` on all calls you |
10 -- make into AceSerializer. | 10 -- make into AceSerializer. |
11 -- @class file | 11 -- @class file |
12 -- @name AceSerializer-3.0 | 12 -- @name AceSerializer-3.0 |
13 -- @release $Id: AceSerializer-3.0.lua 1038 2011-10-03 01:39:58Z mikk $ | 13 -- @release $Id: AceSerializer-3.0.lua 1135 2015-09-19 20:39:16Z nevcairiel $ |
14 local MAJOR,MINOR = "AceSerializer-3.0", 4 | 14 local MAJOR,MINOR = "AceSerializer-3.0", 5 |
15 local AceSerializer, oldminor = LibStub:NewLibrary(MAJOR, MINOR) | 15 local AceSerializer, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
16 | 16 |
17 if not AceSerializer then return end | 17 if not AceSerializer then return end |
18 | 18 |
19 -- Lua APIs | 19 -- Lua APIs |
25 | 25 |
26 -- quick copies of string representations of wonky numbers | 26 -- quick copies of string representations of wonky numbers |
27 local inf = math.huge | 27 local inf = math.huge |
28 | 28 |
29 local serNaN -- can't do this in 4.3, see ace3 ticket 268 | 29 local serNaN -- can't do this in 4.3, see ace3 ticket 268 |
30 local serInf = tostring(inf) | 30 local serInf, serInfMac = "1.#INF", "inf" |
31 local serNegInf = tostring(-inf) | 31 local serNegInf, serNegInfMac = "-1.#INF", "-inf" |
32 | 32 |
33 | 33 |
34 -- Serialization functions | 34 -- Serialization functions |
35 | 35 |
36 local function SerializeStringHelper(ch) -- Used by SerializeValue for strings | 36 local function SerializeStringHelper(ch) -- Used by SerializeValue for strings |
60 res[nres+2] = gsub(v,"[%c \94\126\127]", SerializeStringHelper) | 60 res[nres+2] = gsub(v,"[%c \94\126\127]", SerializeStringHelper) |
61 nres=nres+2 | 61 nres=nres+2 |
62 | 62 |
63 elseif t=="number" then -- ^N = number (just tostring()ed) or ^F (float components) | 63 elseif t=="number" then -- ^N = number (just tostring()ed) or ^F (float components) |
64 local str = tostring(v) | 64 local str = tostring(v) |
65 if tonumber(str)==v --[[not in 4.3 or str==serNaN]] or str==serInf or str==serNegInf then | 65 if tonumber(str)==v --[[not in 4.3 or str==serNaN]] then |
66 -- translates just fine, transmit as-is | 66 -- translates just fine, transmit as-is |
67 res[nres+1] = "^N" | 67 res[nres+1] = "^N" |
68 res[nres+2] = str | 68 res[nres+2] = str |
69 nres=nres+2 | |
70 elseif v == inf or v == -inf then | |
71 res[nres+1] = "^N" | |
72 res[nres+2] = v == inf and serInf or serNegInf | |
69 nres=nres+2 | 73 nres=nres+2 |
70 else | 74 else |
71 local m,e = frexp(v) | 75 local m,e = frexp(v) |
72 res[nres+1] = "^F" | 76 res[nres+1] = "^F" |
73 res[nres+2] = format("%.0f",m*2^53) -- force mantissa to become integer (it's originally 0.5--0.9999) | 77 res[nres+2] = format("%.0f",m*2^53) -- force mantissa to become integer (it's originally 0.5--0.9999) |
145 end | 149 end |
146 | 150 |
147 local function DeserializeNumberHelper(number) | 151 local function DeserializeNumberHelper(number) |
148 --[[ not in 4.3 if number == serNaN then | 152 --[[ not in 4.3 if number == serNaN then |
149 return 0/0 | 153 return 0/0 |
150 else]]if number == serNegInf then | 154 else]]if number == serNegInf or number == serNegInfMac then |
151 return -inf | 155 return -inf |
152 elseif number == serInf then | 156 elseif number == serInf or number == serInfMac then |
153 return inf | 157 return inf |
154 else | 158 else |
155 return tonumber(number) | 159 return tonumber(number) |
156 end | 160 end |
157 end | 161 end |