View Single Post
01-25-14, 09:06 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
I found Phanx's explanation interesting myself and have dabbled with that side of things today to see how it all worked as I've never used tables to hold event and handler functions before so handy to know how they can be used. Here follows my understanding of how it all works. I'm sure others will be able to offer better explanations but here goes anyway.


1. When you use the pairs function you are asking it to grab a key,value pair from the table listed.

Lua Code:
  1. local displayEvents = {
  2.         health = {
  3.             UNIT_HEALTH = true,
  4.             UNIT_MAXHEALTH = true,
  5.         },
  6.         name = {
  7.             PLAYER_TARGET_CHANGED = false,
  8.             UNIT_NAME_UPDATE = true,
  9.         },
  10.     }

In this example the keys are health and name and the values are the values after the '=' in otherwords the table of events and whether they are unitSpecific ( true/false). As far as I am aware these could be written as :
displayEvents[health][UNIT_HEALTH] = true
displayEvents["health"]["UNIT_HEALTH"] = true
displayEvents.health["UNIT_HEALTH"] = true
displayEvents.health.unit_health = true

However if health or UNIT_HEALTH had been previously set to other values such as health = 123. Then displayEvents[health] may ( I think ) be translated as displayEvents[123] but I could be wrong.

From what I understand words do not need to be contained in speech marks as it is automatically treated as a string.

edit: Torhal's explanation was a might bit better than mine.

Lua Code:
  1. for event, unitSpecific in pairs(events) do
  2.             if unitSpecific then
  3.                 f:RegisterUnitEvent(event, unit)
  4.             else
  5.                 f:RegisterEvent(event)
  6.             end
  7.         end

In this example we are asking the addon to look at the events list for selected key earlier requested and check to see if the event ( key ) is a unitSpecific event ( value ). Dependant on that result will be whether it registers the unit event or the regular event.

2. Is answered in the above explanation.

3. I am not sure myself why the hp is queried twice but the hp and hp > 0 is just making sure that there is a hp value and if there is a value that it is more than 0.

4. You are correct in that statement. The frame is passed to the event handler and if the event passes the unit to the handler itself it will use that, otherwise it will use the one that was stored when creating the frame.


I hope that helps you understand things a bit more. The wowpedia website has a link to the lua functions wow uses and a link to the lua manual itself so that you can research some more on that subject.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 01-25-14 at 09:12 PM.
  Reply With Quote