Thread Tools Display Modes
12-09-12, 05:20 AM   #1
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
What's the point of ipairs!?

Hey all.

I've discovered that pairs() can be used for integer and string based tables.

When using pairs() with a integer based table, it also still re-evaluates the key numbers if a field is removed during the iteration.

So what's the point of ipairs()?
__________________
__________________
  Reply With Quote
12-09-12, 07:09 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
ipairs() requires the index to start at 1, and stops when there is a nil value, even if there is more entries in the table after said nil value. pairs() iterates through the entire table regardless of index or value.

http://www.wowpedia.org/API_ipairs
http://www.wowpedia.org/API_pairs
  Reply With Quote
12-09-12, 07:11 AM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
http://facepunch.com/showthread.php?t=875909
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
12-09-12, 09:55 AM   #4
Tuller
A Warpwood Thunder Caller
 
Tuller's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 91
Generally, if I have an "array" and I care about ordering, I use ipairs. If I don't care, I use pairs.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » What's the point of ipairs!?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off