WoW:API pairs

Revision as of 15:32, 26 December 2005 by WoWWiki>WoWWiki-Pixel
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Comes from the native LUA API:

Used in loop constructs to iterate through the values of a table, with index beeing anything.

Example:

local random_array = { mug = "coffee", [42] = "universe", true = "false" }
for index,value in pairs(fruits) do 
  if (type(index) == "number") then
     index = tostring(index)
  elseif (type(index) == "boolean") then
    if (index) then
      index = "true"
    else
      index = "false"
    end
  end
  DEFAULT_CHAT_FRAME:AddMessage(index.." : "..value)
end

Result:

 mug : coffee
 42 : universe
 true : false

would be output to the chat window.