/trunk/libs
-- 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. |
--[[----------------------------------------------------------------------------- |
Frame Container |
-------------------------------------------------------------------------------]] |
local Type, Version = "Frame", 22 |
local Type, Version = "Frame", 23 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
self.frame:Show() |
end, |
["EnableResize"] = function(self, state) |
local func = state and "Show" or "Hide" |
self.sizer_se[func](self.sizer_se) |
self.sizer_s[func](self.sizer_s) |
self.sizer_e[func](self.sizer_e) |
end, |
-- called to set an external table to store status in |
["SetStatusTable"] = function(self, status) |
assert(type(status) == "table") |
titletext = titletext, |
statustext = statustext, |
titlebg = titlebg, |
sizer_se = sizer_se, |
sizer_s = sizer_s, |
sizer_e = sizer_e, |
content = content, |
frame = frame, |
type = Type |
-- end |
-- @class file |
-- @name AceAddon-3.0.lua |
-- @release $Id: AceAddon-3.0.lua 980 2010-10-27 14:20:11Z nevcairiel $ |
-- @release $Id: AceAddon-3.0.lua 1036 2011-08-16 22:45:05Z nevcairiel $ |
local MAJOR, MINOR = "AceAddon-3.0", 10 |
local MAJOR, MINOR = "AceAddon-3.0", 11 |
local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceAddon then return end -- No Upgrade needed. |
-- Event Handling |
local function onEvent(this, event, arg1) |
if event == "ADDON_LOADED" or event == "PLAYER_LOGIN" then |
-- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up |
if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_DebugTools") or event == "PLAYER_LOGIN" then |
-- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration |
while(#AceAddon.initializequeue > 0) do |
local addon = tremove(AceAddon.initializequeue, 1) |
-- end |
-- @class file |
-- @name AceDB-3.0.lua |
-- @release $Id: AceDB-3.0.lua 940 2010-06-19 08:01:47Z nevcairiel $ |
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 21 |
-- @release $Id: AceDB-3.0.lua 1035 2011-07-09 03:20:13Z kaelten $ |
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 22 |
local AceDB, oldminor = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR) |
if not AceDB then return end -- No upgrade needed |
local _, raceKey = UnitRace("player") |
local factionKey = UnitFactionGroup("player") |
local factionrealmKey = factionKey .. " - " .. realmKey |
local factionrealmregionKey = factionrealmKey .. " - " .. string.sub(GetCVar("realmList"), 1, 2):upper() |
local localeKey = GetLocale():lower() |
-- Actual database initialization function |
local function initdb(sv, defaults, defaultProfile, olddb, parent) |
-- Generate the database keys for each section |
["race"] = raceKey, |
["faction"] = factionKey, |
["factionrealm"] = factionrealmKey, |
["factionrealmregion"] = factionrealmregionKey, |
["profile"] = profileKey, |
["locale"] = localeKey, |
["global"] = true, |
["profiles"] = true, |
} |
for db in pairs(AceDB.db_registry) do |
db.callbacks:Fire("OnDatabaseShutdown", db) |
db:RegisterDefaults(nil) |
-- cleanup sections that are empty without defaults |
local sv = rawget(db, "sv") |
for section in pairs(db.keys) do |
debugstack = debug.traceback |
strmatch = string.match |
loadfile("../LibStub.lua")() |
for major, library in LibStub:IterateLibraries() do |
-- check that MyLib doesn't exist yet, by iterating through all the libraries |
assert(major ~= "MyLib") |
end |
assert(not LibStub:GetLibrary("MyLib", true)) -- check that MyLib doesn't exist yet by direct checking |
assert(not pcall(LibStub.GetLibrary, LibStub, "MyLib")) -- don't silently fail, thus it should raise an error. |
local lib = LibStub:NewLibrary("MyLib", 1) -- create the lib |
assert(lib) -- check it exists |
assert(rawequal(LibStub:GetLibrary("MyLib"), lib)) -- verify that :GetLibrary("MyLib") properly equals the lib reference |
assert(LibStub:NewLibrary("MyLib", 2)) -- create a new version |
local count=0 |
for major, library in LibStub:IterateLibraries() do |
-- check that MyLib exists somewhere in the libraries, by iterating through all the libraries |
if major == "MyLib" then -- we found it! |
count = count +1 |
assert(rawequal(library, lib)) -- verify that the references are equal |
end |
end |
assert(count == 1) -- verify that we actually found it, and only once |
debugstack = debug.traceback |
strmatch = string.match |
loadfile("../LibStub.lua")() |
local proxy = newproxy() -- non-string |
assert(not pcall(LibStub.NewLibrary, LibStub, proxy, 1)) -- should error, proxy is not a string, it's userdata |
local success, ret = pcall(LibStub.GetLibrary, proxy, true) |
assert(not success or not ret) -- either error because proxy is not a string or because it's not actually registered. |
assert(not pcall(LibStub.NewLibrary, LibStub, "Something", "No number in here")) -- should error, minor has no string in it. |
assert(not LibStub:GetLibrary("Something", true)) -- shouldn't've created it from the above statement |
debugstack = debug.traceback |
strmatch = string.match |
loadfile("../LibStub.lua")() |
-- Pretend like loaded libstub is old and doesn't have :IterateLibraries |
assert(LibStub.minor) |
LibStub.minor = LibStub.minor - 0.0001 |
LibStub.IterateLibraries = nil |
loadfile("../LibStub.lua")() |
assert(type(LibStub.IterateLibraries)=="function") |
-- Now pretend that we're the same version -- :IterateLibraries should NOT be re-created |
LibStub.IterateLibraries = 123 |
loadfile("../LibStub.lua")() |
assert(LibStub.IterateLibraries == 123) |
-- Now pretend that a newer version is loaded -- :IterateLibraries should NOT be re-created |
LibStub.minor = LibStub.minor + 0.0001 |
loadfile("../LibStub.lua")() |
assert(LibStub.IterateLibraries == 123) |
-- Again with a huge number |
LibStub.minor = LibStub.minor + 1234567890 |
loadfile("../LibStub.lua")() |
assert(LibStub.IterateLibraries == 123) |
print("OK") |
debugstack = debug.traceback |
strmatch = string.match |
loadfile("../LibStub.lua")() |
local lib, oldMinor = LibStub:NewLibrary("Pants", 1) -- make a new thingy |
assert(lib) -- should return the library table |
assert(not oldMinor) -- should not return the old minor, since it didn't exist |
-- the following is to create data and then be able to check if the same data exists after the fact |
function lib:MyMethod() |
end |
local MyMethod = lib.MyMethod |
lib.MyTable = {} |
local MyTable = lib.MyTable |
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 1) -- try to register a library with the same version, should silently fail |
assert(not newLib) -- should not return since out of date |
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 0) -- try to register a library with a previous, should silently fail |
assert(not newLib) -- should not return since out of date |
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 2) -- register a new version |
assert(newLib) -- library table |
assert(rawequal(newLib, lib)) -- should be the same reference as the previous |
assert(newOldMinor == 1) -- should return the minor version of the previous version |
assert(rawequal(lib.MyMethod, MyMethod)) -- verify that values were saved |
assert(rawequal(lib.MyTable, MyTable)) -- verify that values were saved |
local newLib, newOldMinor = LibStub:NewLibrary("Pants", "Blah 3 Blah") -- register a new version with a string minor version (instead of a number) |
assert(newLib) -- library table |
assert(newOldMinor == 2) -- previous version was 2 |
local newLib, newOldMinor = LibStub:NewLibrary("Pants", "Blah 4 and please ignore 15 Blah") -- register a new version with a string minor version (instead of a number) |
assert(newLib) |
assert(newOldMinor == 3) -- previous version was 3 (even though it gave a string) |
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 5) -- register a new library, using a normal number instead of a string |
assert(newLib) |
assert(newOldMinor == 4) -- previous version was 4 (even though it gave a string) |
------------------------------------------------------------------------ |
r152 | torhal | 2011-04-27 08:11:19 +0000 (Wed, 27 Apr 2011) | 1 line |
Changed paths: |
A /tags/r152-release (from /trunk:151) |
Tagging as r152-release |
------------------------------------------------------------------------ |
r151 | torhal | 2011-04-27 08:09:30 +0000 (Wed, 27 Apr 2011) | 1 line |
Changed paths: |
M /trunk/LibQTip-1.0.toc |
Updated ToC version for WoW 4.1 |
------------------------------------------------------------------------ |
--- **AceLocale-3.0** manages localization in addons, allowing for multiple locale to be registered with fallback to the base locale for untranslated strings. |
-- @class file |
-- @name AceLocale-3.0 |
-- @release $Id: AceLocale-3.0.lua 1005 2011-01-29 14:19:43Z mikk $ |
local MAJOR,MINOR = "AceLocale-3.0", 5 |
-- @release $Id: AceLocale-3.0.lua 1035 2011-07-09 03:20:13Z kaelten $ |
local MAJOR,MINOR = "AceLocale-3.0", 6 |
local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
-- Lua APIs |
local assert, tostring, error = assert, tostring, error |
local setmetatable, rawset, rawget = setmetatable, rawset, rawget |
local getmetatable, setmetatable, rawset, rawget = getmetatable, setmetatable, rawset, rawget |
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded |
-- List them here for Mikk's FindGlobals script |
__index = assertfalse |
}) |
-- This metatable proxy is used when registering the default locale. |
-- This metatable proxy is used when registering the default locale. |
-- It refuses to overwrite existing values |
-- Reason 1: Allows loading locales in any order |
-- Reason 2: If 2 modules have the same string, but only the first one to be |
-- Reason 2: If 2 modules have the same string, but only the first one to be |
-- loaded has a translation for the current locale, the translation |
-- doesn't get overwritten. |
-- |
-- L["string1"] = "Zeichenkette1" |
-- @return Locale Table to add localizations to, or nil if the current locale is not required. |
function AceLocale:NewLocale(application, locale, isDefault, silent) |
-- GAME_LOCALE allows translators to test translations of addons without having that wow client installed |
local gameLocale = GAME_LOCALE or gameLocale |
local app = AceLocale.apps[application] |
if silent and app then |
if silent and app and getmetatable(app) ~= readmetasilent then |
geterrorhandler()("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' must be specified for the first locale registered") |
end |
if not app then |
if silent=="raw" then |
app = {} |
AceLocale.apps[application] = app |
AceLocale.appnames[app] = application |
end |
if locale ~= gameLocale and not isDefault then |
return -- nop, we don't need these translations |
end |
registering = app -- remember globally for writeproxy and writedefaultproxy |
if isDefault then |
return writedefaultproxy |
end |