WoW:API pairs

From AddOn Studio
Revision as of 11:19, 27 November 2014 by 99.167.93.136 (talk) (fixed mistake in example results, replaced 'true' with 'testboolean'.)
Jump to navigation Jump to search

WoW Lua

Returns an iterator triple that allows for loops to iterate over all key/value pairs in a table.

iteratorFunc, table, startState = pairs(table);

Example

local random_array = { mug = "coffee", [42] = "universe", testboolean = false }

for index,value in pairs(random_array) 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
 testboolean : false

would be output to the chat window.