Welcome to LibWho-2.0!
This documentation is for developers, it you're a user: just don't care.
- An Interface for a information's about an user
- Better event for who's
- Queuing of /who and SendWho()
- A much better who interface, with guarantee to be executed & callback
This version is 2.0, please do not run them together with 1.0 or other who libraries.
Usage
There are two ways of using WhoLib: embedding into an object or using the library directly
Embedded
-- 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
External
-- 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.
API Documentation
lib:Embed(handler)
Args
- handler
- table - embed the public functions/constants in the object specified by handler
Returns
- nil
Example
LibStub:GetLibaray('LibWho-2.0'):Embed(self)
lib:Library()
Returns
- table - the library
Example
LibStub:GetLibaray('LibWho-2.0'):Library()
:UserInfo(name [, opts])
Args
- name
- string - the exact name of an player
- opts
- optional, table - options
- opts.queue
- optional, number - queue of this query (see below) - .WHOLIB_QUEUE_QUIET (default) or .WHOLIB_QUEUE_SCANNING
- opts.timeout
- optional, number - if the the result is cached, and not older than opts.timeout minutes the cache will be returned, negative value: always use cache (if available), otherwise: send a who query, default: 5 (minutes)
- opts.callback, opts.handler
- optional, callback - see "Callback info" below
- opts.flags
- optional, number - one of more flags or'ed together, see Flags (bit.bor(flag1, flag2 [, flag3 [, ...]]))
Returns
- nil
- if there was no appropriate cache
- false
- see Flags: WHOLIB_FLAG_ALWAYS_CALLBACK
- user, time
- for cached results
- user
- table - the user's information's
- user.Name
- string - name of the player
- user.Online
- true if online, false if offline, nil if unknown (more results than could be displayed)
- if Online is not true than all following entries will be from the last successful call, or nil
- user.Guild
- string - guild or ''
- user.Class
- string - class
- user.Race
- string - race
- user.Level
- string - level
- user.Zone
- string - zone
- time
- number - the minutes how old the data was
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!
Callback
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.
Flags
- .WHOLIB_FLAG_ALWAYS_CALLBACK
- if :UserInfo() would return the cached data, raise the callback immediately with that data instead returning and then return false
Example
-- 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
:CachedUserInfo(name)
Args
- name
- string - the exact name of an player
Returnes
- nil
- if there was no appropriate cache
- user, time
- for cached results
- identical to :UserInfo()
:RegisterWhoLibEvent(event, callback [,handler])
Args
- event
- string - the event you are want to be registered for
- callback, handler
- callback - see "Callback info" below
Returns
- nil
Example
see "Events" below
:Who(query [ , opts])
Args
- query
- string - the search string
- opts
- optional, table - options
- opts.queue
- optional, number - queue of this query (see below) - .WHOLIB_QUEUE_QUIET (default) or .WHOLIB_QUEUE_USER or .WHOLIB_QUEUE_SCANNING
- opts.callback, opts.handler
- optional, callback - see "Callback info" below
Returns
- nil
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.
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.
Example
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.)
Constants
.WHOLIB_QUEUE_USER
.WHOLIB_QUEUE_QUIET
.WHOLIB_QUEUE_SCANNING
.WHOLIB_FLAG_ALWAYS_CALLBACK
Callback info
Some WhoLib functions accepts callbacks, you have always two ways using them.
Using a function
- callback
- function - just point to the function, which should be called
- handler
- nil - must be nil
Example 1
local function eventmanager(event, a1, a2, ...)
-- has no 'self'
end
wholib:RegisterWhoLibEvent('WHOLIB_QUERY_RESULT', eventmanager)
Example 2
function mod.eventmanager(event, a1, a2, ...)
-- has no 'self'
end
wholib:RegisterWhoLibEvent('WHOLIB_QUERY_RESULT', mod.eventmanager)
Using a method
- callback
- string - the name of the method, which should be called
- handler
- table - the object on which the method should be called, if nil the calling object is used
Example
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)
Events
Event: WHOLIB_QUERY_RESULT - query, results, complete, name
Args
- query
- string - search string
- results
- table - table of results
- results[i].Name
- string - name of the player
- results[i].Online
- true if online, false if offline, nil if unknown (more results than could be displayed)
- results[i].Guild
- string - guild or ''
- results[i].Class
- string - class
- results[i].Race
- string - race
- results[i].Level
- string - level
- results[i].Zone
- string - zone
- complete
- boolean - shows whether all results could be returned (true) or not (false), if not, do a more specific query
- name
- string - if the query was initiated by a :UserInfo() call, then this is the player name of the :UserInfo() call, otherwise nil
All these fields are returned when any one call "/who" "SendWho()" or :Who(), even when the results are displayed in the chat.
Example
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
Queues
WHOLIB_QUEUE_USER
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.
WHOLIB_QUEUE_QUIET
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)
WHOLIB_QUEUE_SCANNING
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.
Debug
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.
:SetWhoLibDebug(state)
Args
- state
- boolean - Enables or disables the debugging
Returns
- nil
/wholibdebug
Toggles the debugging.
TODO
- localization
- maybe better English texts
- cleaning code?
- see WHOLIB_QUEUE_QUIET's TODO
If someone wants to help me, just drop a note - or do it!
ALeX Kazik - alx@kazik.de
------------------------------------------------------------------------
r74 | sylvanaar | 2009-04-14 12:38:19 +0000 (Tue, 14 Apr 2009) | 1 line
Changed paths:
A /tags/2.0.2 (from /trunk:73)
Tagging as 2.0.2
------------------------------------------------------------------------
r73 | sylvanaar | 2009-04-14 12:31:44 +0000 (Tue, 14 Apr 2009) | 1 line
Changed paths:
M /trunk/LibWho-2.0.toc
TOC 30100
------------------------------------------------------------------------
r71 | sylvanaar | 2009-04-06 05:57:37 +0000 (Mon, 06 Apr 2009) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
fix a leaked global
------------------------------------------------------------------------
r70 | sylvanaar | 2008-12-27 23:59:35 +0000 (Sat, 27 Dec 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
removed some debug prints that were spammy. broke out the code which updated the relative chance to run for the queues into a separate function
------------------------------------------------------------------------
r69 | sylvanaar | 2008-12-27 23:27:45 +0000 (Sat, 27 Dec 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
replaced the priority queue implementation with a weighted random scheduler to prevent starvation when non wholib addons run massive numbers of queries
------------------------------------------------------------------------
r68 | sylvanaar | 2008-12-27 16:00:50 +0000 (Sat, 27 Dec 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
corrected major bug re: ambiguous self usage. Lua fails for this..
------------------------------------------------------------------------
r67 | akazik | 2008-12-19 19:22:53 +0000 (Fri, 19 Dec 2008) | 2 lines
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
- fixed lib['ebmed'] (Ticket #2)
------------------------------------------------------------------------
r66 | eblume | 2008-12-19 08:32:22 +0000 (Fri, 19 Dec 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
* Fix of Lua error in Embed routine. See comment in file.
------------------------------------------------------------------------
r64 | sylvanaar | 2008-11-15 18:17:23 +0000 (Sat, 15 Nov 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
make sure queries entering the queue get timestamped
------------------------------------------------------------------------
r63 | sylvanaar | 2008-11-15 15:33:39 +0000 (Sat, 15 Nov 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
add the locale neutral name to the cache
------------------------------------------------------------------------
r61 | sylvanaar | 2008-11-11 05:15:14 +0000 (Tue, 11 Nov 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
add libstub check, and version number for copies retrieved from svn
------------------------------------------------------------------------
r59 | sylvanaar | 2008-11-11 04:57:22 +0000 (Tue, 11 Nov 2008) | 1 line
Changed paths:
M /trunk/LibWho-2.0/LibWho-2.0.lua
M /trunk/LibWho-2.0.toc
fix the callback bug again, and tweak the replacement strings for versioning
------------------------------------------------------------------------
r58 | sylvanaar | 2008-11-11 04:43:02 +0000 (Tue, 11 Nov 2008) | 1 line
Changed paths:
A /trunk/.pkgmeta
A /trunk/LibWho-2.0
A /trunk/LibWho-2.0/LibWho-2.0.lua
A /trunk/LibWho-2.0.toc
hello LibWho-2.0
------------------------------------------------------------------------
r57 | sylvanaar | 2008-11-11 04:40:04 +0000 (Tue, 11 Nov 2008) | 1 line
Changed paths:
M /trunk
D /trunk/.pkgmeta
D /trunk/Documentation.url
D /trunk/WhoLib-1.0
D /trunk/WhoLib.toc
D /trunk/libs
adios
------------------------------------------------------------------------
r55 | sylvanaar | 2008-10-16 05:41:12 +0000 (Thu, 16 Oct 2008) | 1 line
Changed paths:
M /trunk/WhoLib-1.0/WhoLib-1.0.lua
Make the hook of OnEvent use the passed frame and event
------------------------------------------------------------------------
r54 | nevcairiel | 2008-10-09 21:54:52 +0000 (Thu, 09 Oct 2008) | 1 line
Changed paths:
M /trunk/WhoLib-1.0/WhoLib-1.0.lua
WoWAce Post-Processing: Virtually inflate Library Revision numbers for proper upgrade path
------------------------------------------------------------------------
r53 | root | 2008-09-30 16:16:49 +0000 (Tue, 30 Sep 2008) | 1 line
Changed paths:
M /trunk/.pkgmeta
Hopefully fix .pkgmeta
------------------------------------------------------------------------
r52 | root | 2008-09-29 22:07:10 +0000 (Mon, 29 Sep 2008) | 1 line
Changed paths:
A /trunk/.pkgmeta
M /trunk/libs
Facilitate WowAce-on-CurseForge transition
------------------------------------------------------------------------
r50 | root | 2008-09-29 20:58:53 +0000 (Mon, 29 Sep 2008) | 1 line
Changed paths:
D /tmp/trunk/WhoLib
A /trunk (from /tmp/trunk/WhoLib:49)
Importing old repo data under /trunk
------------------------------------------------------------------------
r47 | alx | 2008-07-22 16:45:47 +0000 (Tue, 22 Jul 2008) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib: TOC and email update
------------------------------------------------------------------------
r46 | StingerSoft | 2008-07-21 07:41:25 +0000 (Mon, 21 Jul 2008) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib: addad ruRU strings
------------------------------------------------------------------------
r45 | sylvanaar | 2008-07-11 04:57:43 +0000 (Fri, 11 Jul 2008) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib: Fix for case where arg1 is nil during CHAT_MSG_SYSTEM. Most likely caused by a ChatFrame_AddMessageEventHandler filter.
------------------------------------------------------------------------
r44 | anea | 2008-05-14 19:27:12 +0000 (Wed, 14 May 2008) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib: Never try to outsmart a whole community :P Changed line 501 to use Deformat as suggested, which will also fix the error on line 296.
------------------------------------------------------------------------
r43 | anea | 2008-05-14 09:29:03 +0000 (Wed, 14 May 2008) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib:
- Fixed error on line 501
------------------------------------------------------------------------
r40 | Octane666 | 2008-03-12 19:25:56 +0000 (Wed, 12 Mar 2008) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib:
- Corrected bug in UserInfo() where it was incorrectly determining the type of args.callback meant that the callback wasn't being called for cached entries even if WHOLIB_FLAG_ALLWAYS_CALLBACK was set.
------------------------------------------------------------------------
r39 | sylvanaar | 2008-02-21 02:20:15 +0000 (Thu, 21 Feb 2008) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib: Added obnoxious number of nil checks to ReturnUserInfo so it will shut up.
------------------------------------------------------------------------
r38 | Octane666 | 2008-02-19 00:43:02 +0000 (Tue, 19 Feb 2008) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib:
- This library will no longer cause errors when upgrading older versions of itself. Previously it would cause errors when trying to re-hook functions that a previous version of the library had already hooked. The author's wiki says he's happy for people to fix this library... so here's a fix :P
------------------------------------------------------------------------
r37 | sylvanaar | 2008-02-17 11:04:29 +0000 (Sun, 17 Feb 2008) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib: Set the default mode to stop background queries while the friendsframe is open
------------------------------------------------------------------------
r36 | sylvanaar | 2008-02-17 08:45:01 +0000 (Sun, 17 Feb 2008) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib: Fix likely bug when 2 addons embed WhoLib and an upgrade occurs. (Drycode)
------------------------------------------------------------------------
r35 | alx | 2007-12-24 22:12:06 +0000 (Mon, 24 Dec 2007) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib: updated toc
------------------------------------------------------------------------
r34 | gandharva | 2007-10-23 20:55:04 +0000 (Tue, 23 Oct 2007) | 1 line
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib: attempt to fix nil error
------------------------------------------------------------------------
r33 | alx | 2007-10-03 09:10:09 +0000 (Wed, 03 Oct 2007) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib:
- updated toc
------------------------------------------------------------------------
r32 | alx | 2007-07-28 16:41:52 +0000 (Sat, 28 Jul 2007) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib:
- two fixes in :UserInfo()
------------------------------------------------------------------------
r31 | alx | 2007-05-23 08:29:57 +0000 (Wed, 23 May 2007) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib:
- updated toc to 20100 (2.1)
------------------------------------------------------------------------
r30 | funkydude | 2007-05-20 23:37:12 +0000 (Sun, 20 May 2007) | 1 line
Changed paths:
M /tmp/trunk/WhoLib
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib: LoD
------------------------------------------------------------------------
r29 | alx | 2007-05-14 17:18:11 +0000 (Mon, 14 May 2007) | 3 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib.toc
A /tmp/trunk/WhoLib/libs
WhoLib:
- embedded libs
- updated toc
------------------------------------------------------------------------
r28 | alx | 2007-05-13 18:51:11 +0000 (Sun, 13 May 2007) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib:
- fixed a bug in the localisation
------------------------------------------------------------------------
r27 | alx | 2007-05-13 10:34:01 +0000 (Sun, 13 May 2007) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib:
- fixed a bug concerning UserInfo()
------------------------------------------------------------------------
r26 | alx | 2007-05-12 11:01:51 +0000 (Sat, 12 May 2007) | 1 line
Changed paths:
A /tmp/trunk/WhoLib/Documentation.url
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib: major changes (see docs)
------------------------------------------------------------------------
r25 | alx | 2007-05-07 08:11:46 +0000 (Mon, 07 May 2007) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib:
- renamed :SetDebug() to :SetWhoLibDebug()
------------------------------------------------------------------------
r24 | alx | 2007-05-05 19:28:57 +0000 (Sat, 05 May 2007) | 3 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
WhoLib:
- fixed WhoFrame problem
- added debug support (see documentation)
------------------------------------------------------------------------
r23 | alx | 2007-05-03 21:55:57 +0000 (Thu, 03 May 2007) | 2 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib:
- fixed $Revision
------------------------------------------------------------------------
r22 | alx | 2007-05-03 21:26:52 +0000 (Thu, 03 May 2007) | 4 lines
Changed paths:
M /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua
M /tmp/trunk/WhoLib/WhoLib.toc
WhoLib:
- updated toc
- fixed callback
- improved WoW 2.1 compatibility
------------------------------------------------------------------------
r21 | alx | 2007-05-03 21:20:46 +0000 (Thu, 03 May 2007) | 1 line
Changed paths:
A /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib-1.0.lua (from /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib.lua:20
D /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib.lua
WhoLib: cleanup (rename)
------------------------------------------------------------------------
r20 | alx | 2007-05-03 21:17:37 +0000 (Thu, 03 May 2007) | 1 line
Changed paths:
A /tmp/trunk/WhoLib/WhoLib-1.0/WhoLib.lua (from /tmp/trunk/WhoLib/WhoLib.lua:19
D /tmp/trunk/WhoLib/WhoLib.lua
WhoLib: cleanup (move)
------------------------------------------------------------------------
r19 | alx | 2007-05-03 21:16:36 +0000 (Thu, 03 May 2007) | 1 line
Changed paths:
A /tmp/trunk/WhoLib/WhoLib-1.0
WhoLib: cleanup (mkdir)
------------------------------------------------------------------------
r18 | alx | 2007-05-01 17:52:13 +0000 (Tue, 01 May 2007) | 1 line
Changed paths:
A /tmp/trunk/WhoLib/WhoLib.lua
A /tmp/trunk/WhoLib/WhoLib.toc
WhoLib: initial release
------------------------------------------------------------------------
r17 | alx | 2007-05-01 17:44:14 +0000 (Tue, 01 May 2007) | 1 line
Changed paths:
A /tmp/trunk/WhoLib
initial release
------------------------------------------------------------------------