/branches/zhTW_201107/Aloft/Libs
-- make into AceSerializer. |
-- @class file |
-- @name AceSerializer-3.0 |
-- @release $Id: AceSerializer-3.0.lua 910 2010-02-11 21:54:24Z mikk $ |
local MAJOR,MINOR = "AceSerializer-3.0", 3 |
-- @release $Id: AceSerializer-3.0.lua 1038 2011-10-03 01:39:58Z mikk $ |
local MAJOR,MINOR = "AceSerializer-3.0", 4 |
local AceSerializer, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceSerializer then return end |
local tconcat = table.concat |
-- quick copies of string representations of wonky numbers |
local serNaN = tostring(0/0) |
local serInf = tostring(1/0) |
local serNegInf = tostring(-1/0) |
local inf = math.huge |
local serNaN -- can't do this in 4.3, see ace3 ticket 268 |
local serInf = tostring(inf) |
local serNegInf = tostring(-inf) |
-- Serialization functions |
local function SerializeStringHelper(ch) -- Used by SerializeValue for strings |
elseif t=="number" then -- ^N = number (just tostring()ed) or ^F (float components) |
local str = tostring(v) |
if tonumber(str)==v or str==serNaN or str==serInf or str==serNegInf then |
if tonumber(str)==v --[[not in 4.3 or str==serNaN]] or str==serInf or str==serNegInf then |
-- translates just fine, transmit as-is |
res[nres+1] = "^N" |
res[nres+2] = str |
end |
local function DeserializeNumberHelper(number) |
if number == serNaN then |
--[[ not in 4.3 if number == serNaN then |
return 0/0 |
elseif number == serNegInf then |
return -1/0 |
else]]if number == serNegInf then |
return -inf |
elseif number == serInf then |
return 1/0 |
return inf |
else |
return tonumber(number) |
end |
-- make into AceTimer. |
-- @class file |
-- @name AceTimer-3.0 |
-- @release $Id: AceTimer-3.0.lua 895 2009-12-06 16:28:55Z nevcairiel $ |
-- @release $Id: AceTimer-3.0.lua 1037 2011-09-02 16:24:08Z mikk $ |
--[[ |
Basic assumptions: |
- ALLOWS unscheduling ANY timer (including the current running one) at any time, including during OnUpdate processing |
]] |
local MAJOR, MINOR = "AceTimer-3.0", 5 |
local MAJOR, MINOR = "AceTimer-3.0", 6 |
local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceTimer then return end -- No upgrade needed |
-- Time to clean it out? |
local list = selfs[self] |
if (list.__ops or 0) < 250 then -- 250 slosh indices = ~10KB wasted (max!). For one 'self'. |
if (list.__ops or 0) < 250 then -- 250 slosh indices = ~10KB wasted (worst case!). For one 'self'. |
return |
end |
local n=0 |
for k,v in pairs(list) do |
newlist[k] = v |
n=n+1 |
if type(v)=="table" and v.callback then -- if the timer is actually live: count it |
n=n+1 |
end |
end |
newlist.__ops = 0 -- Reset operation count |
AceTimer.frame:SetScript("OnEvent", OnEvent) |
AceTimer.frame:RegisterEvent("PLAYER_REGEN_ENABLED") |
-- In theory, we should hide&show the frame based on there being timers or not. |
-- In theory, we could hide&show the frame based on there being timers or not. |
-- However, this job is fairly expensive, and the chance that there will |
-- actually be zero timers running is diminuitive to say the lest. |
-- actually be zero timers running is diminuitive to say the least. |