Welcome to LibWho-2.0!
This documentation is for developers, it you're a user: just don't care.
This version is 2.0, please do not run them together with 1.0 or other who libraries.
There are two ways of using WhoLib: embedding into an object or using the library directly
-- at the beginning of your addon
LibStub:GetLibaray('LibWho-2.0'):Embed(self)
-- call a function within an method:
function mod:xxx(...)
self:UserInfo(...)
end
-- at the begging of your addon
local wholib = LibStub:GetLibrary('LibWho-2.0'):Library()
-- call a function:
wholib:UserInfo(...)
The examples in this documentation uses the embedded version, but it should be easy to adopt them to external.
LibStub:GetLibaray('LibWho-2.0'):Embed(self)
LibStub:GetLibaray('LibWho-2.0'):Library()
If you're only interested in this feature, then you don't have to read about :Who() and WHOLIB_QUERY_RESULT.
Do not use .WHOLIB_FLAG_ALWAYS_CALLBACK when scanning a list over and over again, do a 5 sec pause after a
cached return, cause you may have a short list and a cache time so high that all entries may be cached
and in that case this function DO generate an almost infinite loop!
When a callback function is given and the function didn't returned immediately then the callback will be raised when they're a result. The callback function will receive the same arguments as :UserInfo() would return.
-- long version
local user, time = self:UserInfo(friendsname, { callback = 'UserDataReturned' } )
if user then
-- the data was immediately available
self:UserDataReturned(user, time)
else
-- nothing
-- we will be called when the data is available
end
-- short version
self:UserData(friendsname, { callback = 'UserDataReturned', flags = self.WHOLIB_FLAG_ALWAYS_CALLBACK } )
-- callback function
function mod:UserDataReturned(user, time)
local state
if user.Online == true then
state = 'Online'
elseif user.Online == false then
state = 'Offline'
else
-- user.Online is nil
state = 'Unknown'
end
DEFAULT_CHAT_FRAME:AddMessage(user.Name .. ' is ' .. state)
end
see "Events" below
Everything except query will be ignored when the queue is .WHOLIB_QUEUE_USER.
If you've already registered WHOLIB_QUERY_RESULT then you may be don't need a callback.
When a callback function is given then the callback will be raised after the query is executed. The callback function will receive the same arguments as the event :WHOLIB_QUERY_RESULT has.
self:Who({query = 'n-' .. friendsname, queue = self.WHOLIB_QUERY_QUIET, callback = 'DisplayPlayers'})
-- self:DisplayPlayers is in the WHOLIB_QUERY_RESULT example below
If you're only interested in the information of one player, use :UserInfo() instead. (You can set opts.timeout to 0 if you don't accept cached data.)
Some WhoLib functions accepts callbacks, you have always two ways using them.
local function eventmanager(event, a1, a2, ...)
-- has no 'self'
end
wholib:RegisterWhoLibEvent('WHOLIB_QUERY_RESULT', eventmanager)
function mod.eventmanager(event, a1, a2, ...)
-- has no 'self'
end
wholib:RegisterWhoLibEvent('WHOLIB_QUERY_RESULT', mod.eventmanager)
function mod:eventmanager(event, a1, a2, ...)
-- has 'self'
end
mod:RegisterWhoLibEvent('WHOLIB_QUERY_RESULT', 'eventmanager')
-- is equivalent to
wholib:RegisterWhoLibEvent('WHOLIB_QUERY_RESULT', 'eventmanager', self)
All these fields are returned when any one call "/who" "SendWho()" or :Who(), even when the results are displayed in the chat.
function mod:OnEnable()
...
self:RegisterWhoLibEvent('WHOLIB_QUERY_RESULT', 'DisplayPlayers', self)
...
end
function mod:DisplayPlayers(query, results, complete)
if not complete then
DEFAULT_CHAT_FRAME:AddMessage('There were more Players than here shown!')
end
for _,result in pairs(results) do
DEFAULT_CHAT_FRAME:AddMessage('Player ' .. result.Name .. ' is currently in ' .. result.Zone)
end
end
Used on user queries (e.g. "/who", SocialFrame's Who)
Will display the results in chat if only some, or in who-frame if more.
Should be standard queue for addon queries, which aren't for scanning, and do not result in a user action: use .WHOLIB_QUEUE_USER.
Will neither show chat messages nor who-frame.
Will be slowly queried while the WhoFrame is open. (TODO)
Use for scanning.
Will neither show chat messages nor who-frame.
Will not be queried while the WhoFrame is open.
At first the .WHOLIB_QUEUE_USER queries will be executed, then the .WHOLIB_QUEUE_QUIET and at last the .WHOLIB_QUEUE_SCANNING.
When debugging is enabled then the chat will be filled with added/returned entries, one for each query.
21:01:40 WhoLib: [3] added "n-Lager", queues=0, 0, 1 21:01:40 WhoLib: [3] returned "n-Lager", total=0, queues=0, 0, 0
The [3] means Queue 3 = WHOLIB_QUEUE_SCANNING, each query will at first be "added" and later "returned",
on returned queries the total number of entries will also be printed.
The "queues=0, 0, 1" means that 0 queries are in the .WHOLIB_QUEUE_USER queue,
0 in .WHOLIB_QUEUE_QUIET, and 1 (the added one) in .WHOLIB_QUEUE_SCANNING.
For :UserInfo() even more entries will be printed.
Toggles the debugging.
If someone wants to help me, just drop a note - or do it!
ALeX Kazik - alx@kazik.de
© 2008-2009 Curse Inc.
- #1
eblume Fri, 19 Dec 2008 08:37:16Hello,
I am interested in becoming an author of this project. My own addon, Socialist, uses it extensively, and I am interested in enhancing WhoLib for my own (not at all diabolic) uses. If that helps others at the same time, then so be it.
Thank you, Erich