Thread: UnitAura API
View Single Post
04-17-18, 12:37 PM   #13
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
lua Code:
  1. local t = {
  2.   Magic = "M",
  3.   ["Poison"] = "P",
  4. }
  5.  
  6. local dispel = "Magic"
  7.  
  8. print(t.Magic)
  9. print(t["Magic"])
  10. print(t[dispel])
  11.  
  12. dispel = "Poison"
  13.  
  14. print(t.Poison)
  15. print(t["Poison"])
  16. print(t[dispel])

The output is:
Code:
M
M
M
P
P
P
t.Magic is just syntactic sugar for t["Magic"]. Beware t[dispel] - it is not the same as t["dispel"] - without the quotation marks it is the variable dispel, that contains the string value "Magic", with the quotation marks it is a string literal and thus a key named "dispel" will be looked up (which does not exist in the example)

lua Code:
  1. local t = { "Curse" = "C" } -- INVALID SYNTAX
  Reply With Quote