WoW:API ipairs: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
 
mNo edit summary
Line 1: Line 1:
Wrapper for lua function ipairs(t):
Comes from the native LUA API:


Used in loop constructs to iterate through the values of a table where there is no index (an array).
Used in loop constructs to iterate through the values of a table where the index are only numbers, or where there is no index (an array).


Example:
Example:


  local fruits={"apple","orange","banana",kiwi"}
  local fruits={"apple","orange","banana","kiwi"}


  for index,value in ipairs(fruits) do  
  for index,value in ipairs(fruits) do  

Revision as of 15:28, 26 December 2005

Comes from the native LUA API:

Used in loop constructs to iterate through the values of a table where the index are only numbers, or where there is no index (an array).

Example:

local fruits={"apple","orange","banana","kiwi"}
for index,value in ipairs(fruits) do 
  DEFAULT_CHAT_FRAME:AddMessage(tostring(index).." : "..value)
end

Result:

 1 : apple
 2 : orange
 3 : banana
 4 : kiwi

would be output to the chat window.