WoW:API pairs: Difference between revisions
Jump to navigation
Jump to search
(a string can not be called true! and it wasn't a boolean.) |
({{luaapi}}) |
||
Line 1: | Line 1: | ||
{{luaapi}} | |||
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 } | local random_array = { mug = "coffee", [42] = "universe", testboolean = false } | ||
Line 27: | Line 26: | ||
would be output to the chat window. | would be output to the chat window. | ||
Revision as of 23:04, 25 March 2010
← 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 true : false
would be output to the chat window.