annotate Libs/LibDataBroker-1.1/LibDataBroker-1.1.lua @ 0:fc346da3afd9

First commit Hot Corners standalone.
author tercio
date Fri, 08 Aug 2014 12:35:17 -0300
parents
children 9ad7f3c634f1
rev   line source
tercio@0 1
tercio@0 2 assert(LibStub, "LibDataBroker-1.1 requires LibStub")
tercio@0 3 assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibDataBroker-1.1 requires CallbackHandler-1.0")
tercio@0 4
tercio@0 5 local lib, oldminor = LibStub:NewLibrary("LibDataBroker-1.1", 3)
tercio@0 6 if not lib then return end
tercio@0 7 oldminor = oldminor or 0
tercio@0 8
tercio@0 9
tercio@0 10 lib.callbacks = lib.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
tercio@0 11 lib.attributestorage, lib.namestorage, lib.proxystorage = lib.attributestorage or {}, lib.namestorage or {}, lib.proxystorage or {}
tercio@0 12 local attributestorage, namestorage, callbacks = lib.attributestorage, lib.namestorage, lib.callbacks
tercio@0 13
tercio@0 14 if oldminor < 2 then
tercio@0 15 lib.domt = {
tercio@0 16 __metatable = "access denied",
tercio@0 17 __index = function(self, key) return attributestorage[self] and attributestorage[self][key] end,
tercio@0 18 }
tercio@0 19 end
tercio@0 20
tercio@0 21 if oldminor < 3 then
tercio@0 22 lib.domt.__newindex = function(self, key, value)
tercio@0 23 if not attributestorage[self] then attributestorage[self] = {} end
tercio@0 24 if attributestorage[self][key] == value then return end
tercio@0 25 attributestorage[self][key] = value
tercio@0 26 local name = namestorage[self]
tercio@0 27 if not name then return end
tercio@0 28 callbacks:Fire("LibDataBroker_AttributeChanged", name, key, value, self)
tercio@0 29 callbacks:Fire("LibDataBroker_AttributeChanged_"..name, name, key, value, self)
tercio@0 30 callbacks:Fire("LibDataBroker_AttributeChanged_"..name.."_"..key, name, key, value, self)
tercio@0 31 callbacks:Fire("LibDataBroker_AttributeChanged__"..key, name, key, value, self)
tercio@0 32 end
tercio@0 33 end
tercio@0 34
tercio@0 35 if oldminor < 2 then
tercio@0 36 function lib:NewDataObject(name, dataobj)
tercio@0 37 if self.proxystorage[name] then return end
tercio@0 38
tercio@0 39 if dataobj then
tercio@0 40 assert(type(dataobj) == "table", "Invalid dataobj, must be nil or a table")
tercio@0 41 self.attributestorage[dataobj] = {}
tercio@0 42 for i,v in pairs(dataobj) do
tercio@0 43 self.attributestorage[dataobj][i] = v
tercio@0 44 dataobj[i] = nil
tercio@0 45 end
tercio@0 46 end
tercio@0 47 dataobj = setmetatable(dataobj or {}, self.domt)
tercio@0 48 self.proxystorage[name], self.namestorage[dataobj] = dataobj, name
tercio@0 49 self.callbacks:Fire("LibDataBroker_DataObjectCreated", name, dataobj)
tercio@0 50 return dataobj
tercio@0 51 end
tercio@0 52 end
tercio@0 53
tercio@0 54 if oldminor < 1 then
tercio@0 55 function lib:DataObjectIterator()
tercio@0 56 return pairs(self.proxystorage)
tercio@0 57 end
tercio@0 58
tercio@0 59 function lib:GetDataObjectByName(dataobjectname)
tercio@0 60 return self.proxystorage[dataobjectname]
tercio@0 61 end
tercio@0 62
tercio@0 63 function lib:GetNameByDataObject(dataobject)
tercio@0 64 return self.namestorage[dataobject]
tercio@0 65 end
tercio@0 66 end