ParserLib API Documentation

From WowAce Wiki
Jump to: navigation, search

:RegisterEvent("addonID" or addonObject, "event", handler or "handler" or method or "method" )

Register to a Blizzard event.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.
"event"
the Blizzard event.
handler or "handler"
the function / global function name to call back when the even occurred.
method or "method"
if the first arg is a table, then the handler will be expected to be a method.

Example

parser:RegisterEvent(myAddonObject, "CHAT_MSG_COMBAT_SELF_HITS", "OnCombatHit")

:UnregisterEvent("addonID" or addonObject, "event")

Unregister a Blizzard event.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.
"event"
the Blizzard event.

Example

parser:UnregisterEvent(myAddonObject, "CHAT_MSG_COMBAT_SELF_HITS")

:UnregisterAllEvents("addonID" or addonObject)

Unregister all Blizzard events.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.

Example

parser:UnregisterAllEvents(myAddonObject)

:IsEventRegistered("addonID" or addonObject, "event")

Check whether the Blizzard event is registered or not.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.
"event"
the Blizzard event.

Returns

isRegistered

isRegistered 
boolean

Example

local isRegistered = parser:IsEventRegistered(myAddonObject, "CHAT_MSG_COMBAT_SELF_HITS")

:RegisterInfoType("addonID" or addonObject, "type", handler or "handler" or method or "method" )

Similar to RegisterEvent, but register to a specific message type instead. ParserLib will register to all Blizzard events which might fire messages with this type.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.
"type"
the message type.
handler or "handler"
the function / global function name to call back when the even occurred.
method or "method"
if the first arg is a table, then the handler will be expected to be a method.

Example

parser:RegisterInfoType(myAddonObject, "hit", "OnCombatHit")

:UnregisterInfoType("addonID" or addonObject, "type")

Unregister a message type.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.
"type"
the message type.

Example

parser:UnregisterInfoType(myAddonObject, "hit")

:UnregisterAllInfoTypes("addonID" or addonObject)

Unregister all message types.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.

Example

parser:UnregisterAllInfoTypes(myAddonObject)

:IsInfoTypeRegistered("addonID" or addonObject, "type")

Check whether the message type is registered or not.

Args

"addonID"
a unique string representing your addon.
addonObject 
you may also pass a table as the addonID, in this case the handler arg will be treated as a method.
"type"
the message type.

Returns

isRegistered

isRegistered 
boolean

Example

local isRegistered = parser:IsInfoTypeRegistered(myAddonObject, "hit")

:IterateInfoTable()

The info table is a read-only table and cannot be iterated, use this in case you want to iterate through the fields.

Example

for field, value in parser:IterateInfoTable() do
  print(field .. "=" .. value)
end

:Deformat("text", "pattern")

Use this to parse for custom patterns which is not supported by ParserLib.

Args

"text" 
the message to parse.
"pattern" 
the pattern as in string.format.

Returns

...

... 
the string.format tokens parsed in the message.

Example

attacker, victim, amount, element = parser:Deformat("Rophy hits Pig for 500 fire damage.", COMBATHITSCHOOLOTHEROTHER)