API
Last Updated: 2009-01-31 for 1.0.14-alpha
GUID Cache Querying
LibUnitID:GetUnitGUID(unitid)
Returns the UnitID's GUID from the cache.
This is the method-call version of this functionality; it must be called as
a method on a LibUnitID library reference, as in
myLibRef:GetUnitGUID("pet").
Note that the cache is only updated when the library receives event notifications from the game engine, which may happen in any order. If you have your own event handlers for events that affect UnitIDs, and if you try to query the cache during those event handlers, you may receive out-of-date information if the library has not yet received the event and updated itself.
Also note that the library will not track UnitIDs for which nobody has registered a callback, and will also not take the time to verify that when queried; if you request the GUID of a UnitID that you did not register a callback for, you will get nil unless someone else happened to register for that UnitID.
For best results, only query the cache from a callback that you registered with LibUnitID, or during events that do not affect UnitIDs.
Parameters
- unitid
- The UnitID to fetch the GUID for.
Return value
The GUID of the UnitID, or nil if it doesn't exist or isn't being tracked by the library.
LibUnitID.UnitGUID(unitid)
Returns the UnitID's GUID from the cache.
This is the function-call version of this functionality; it must be called
as a bare function, as in myLibRef.UnitGUID("pet"). This is done so
that you can make a local copy of the function reference (as in
local UnitGUID = myLibRef.UnitGUID) and then use it in place of the
default API UnitGUID() function. In all other ways this is equivalent to
:GetUnitGUID(), and all the same caveats apply.
Parameters
- unitid
- The UnitID to fetch the GUID for.
Return value
The GUID of the UnitID, or nil if it doesn't exist or isn't being tracked by the library.
See also
- LibUnitID:GetUnitGUID
Callback Registration
LibUnitID:RegisterAll(callback, handler)
Registers a callback for all supported UnitIDs.
This is equivalent to calling :RegisterUnit() on all UnitIDs that
are supported by LibUnitID.
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered.
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterAllParty(callback, handler)
Registers a callback for all party related UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"party#", "party#target", "partypet#" and "partypet#target" for # 1..5.
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (20 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterAllRaid(callback, handler)
Registers a callback for all raid related UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"raid##", "raid##target", "raidpet##" and "raidpet##target" for ## 1..40.
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (160 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterParty(callback, handler)
Registers a callback for all party-member UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs "party1"
through "party5".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (5 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterPartyPetTargets(callback, handler)
Registers a callback for all party-member-pet-target UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"partypet1target" through "partypet5target".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (5 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterPartyPets(callback, handler)
Registers a callback for all party-member-pet UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"partypet1" through "partypet5".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (5 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterPartyTargets(callback, handler)
Registers a callback for all party-member-target UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"party1target" through "party5target".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (5 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterRaid(callback, handler)
Registers a callback for all raid-member UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs "raid1"
through "raid40".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (40 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterRaidPetTargets(callback, handler)
Registers a callback for all raid-member-pet-target UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"raidpet1target" through "raidpet40target".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (40 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterRaidPets(callback, handler)
Registers a callback for all raid-member-pet UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"raidpet1" through "raidpet40".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (40 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterRaidTargets(callback, handler)
Registers a callback for all raid-member-target UnitIDs.
This is equivalent to calling :RegisterUnit() on the UnitIDs
"raid1target" through "raid40target".
Parameters
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
The number of UnitIDs that were successfully registered (40 possible).
See also
- LibUnitID:RegisterUnit
LibUnitID:RegisterUnit(unitid, callback, handler)
Registers a callback for a single UnitID.
Whenever the identity of the specified UnitID changes, the callback
function will be called. If a handler is provided, it must be a table and
will be given as the first argument to the callback. The next arguments to
the callback will be the name of the game event that triggered the update,
followed by a delta table detailing the UnitIDs that changed.
If a handler is provided, then callback may be specified as a string, which will be resolved on the handler each time the callback is to be called. This is slightly slower but more flexible, since it allows you to redefine the callback function without having to unregister and re-register the function pointer.
Multiple calls with the same unitid, callback and handler have no effect. A single callback may be registered with multiple handlers, and a single handler may be registered with multiple callbacks, and each combination will be called.
If the same callback+handler pair is registered for multiple UnitIDs, and if a single game event causes more than one of those UnitIDs to change identity, the callback will still only be called once. To retrieve information about which UnitIDs actually changed within your callback, check the provided delta table.
Parameters
- unitid
- The UnitID to monitor.
- callback
- A function reference to call, or a string method name to resolve on the handler and then call.
- handler
- (Optional) The first argument to pass to the callback function, and the table to resolve callback on if it is a string.
Return value
True if the callback is successfully registered, false otherwise.
See also
- delta
Callback Unregistration
LibUnitID:UnregisterAll(callback, handler)
Unregisters a callback from all supported UnitIDs.
This is equivalent to calling :UnregisterUnit() on all UnitIDs that
are supported by LibUnitID.
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered.
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterAllParty(callback, handler)
Unregisters a callback from all party related UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"party#", "party#target", "partypet#" and "partypet#target" for # 1..5.
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (20 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterAllRaid(callback, handler)
Unregisters a callback from all raid related UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"raid#", "raid#target", "raidpet#" and "raidpet#target" for # 1..40.
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (160 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterParty(callback, handler)
Unregisters a callback from all party-member UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"party1" through "party5".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (5 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterPartyPetTargets(callback, handler)
Unregisters a callback from all party-member-pet-target UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"partypet1target" through "partypet5target".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (5 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterPartyPets(callback, handler)
Unregisters a callback from all party-member-pet UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"partypet1" through "partypet5".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (5 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterPartyTargets(callback, handler)
Unregisters a callback from all party-member-target UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"party1target" through "party5target".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (5 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterRaid(callback, handler)
Unregisters a callback from all raid-member UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"raid1" through "raid40".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (40 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterRaidPetTargets(callback, handler)
Unregisters a callback from all raid-member-pet-target UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"raidpet1target" through "raidpet40target".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (40 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterRaidPets(callback, handler)
Unregisters a callback from all raid-member-pet UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"raidpet1" through "raidpet40".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (40 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterRaidTargets(callback, handler)
Unregisters a callback from all raid-member-target UnitIDs.
This is equivalent to calling :UnregisterUnit() on the UnitIDs
"raid1target" through "raid40target".
Parameters
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
The number of UnitIDs that were successfully unregistered (40 possible).
See also
- LibUnitID:UnregisterUnit
LibUnitID:UnregisterUnit(unitid, callback, handler)
Unregisters a callback from a single UnitID.
The callback function or method will no longer be called for changes in the
specified UnitID. Callbacks are stored separately and must be unregistered
separately for each callback+handler pair, including whether
callback is a function reference or a string method name.
Parameters
- unitid
- The UnitID to stop monitoring.
- callback
- A function reference or string method name to stop calling.
- handler
- (Optional) The handler associated with the callback to unregister.
Return value
True if the callback is successfully unregistered, false otherwise (including if the callback was not registered for the unitid).
Compatibility
LibUnitID:GetSupportedUnitIDs()
Gets a list of the UnitIDs that the library is able to track and cache.
The returned table contains the supported UnitIDs as both keys and values,
such as {target="target",pet="pet",...}. These are the UnitIDs that
may be registered for callbacks using :RegisterUnit(), and then
queried using :GetUnitGUID() or .UnitGUID().
Return value
A hash table containing the supported UnitIDs.
Delta Table
This table lists the UnitIDs that changed during a single game event. For efficiency, the table is shared and provided to every callback involved during a game event; for safety, that table may not be modified (it __indexes the real table, and errors on __newindex). This means you cannot process it using pairs(), ipairs() or next(). Instead, index 0 of the table will contain the number of affected UnitIDs (the equivalent of the # operator), and indecies 1-# will contain those UnitIDs. In addition, each affected UnitID is a string key of the table, whose value is the boolean true. Please see the project documentation for code examples to process this table in your callback functions.
Fields
- 0
- The number of UnitIDs that changed.
- (n) (Integer)
- For n = 1 .. delta[0], delta[n] is a UnitID that changed.
- (unitid) (String)
- For unitid in { delta[1] .. delta[delta[0]] }, delta[unitid]=true.
Last Updated: 2009-01-31 for 1.0.14-alpha
Comments