Reply
 
Thread Tools Display Modes
Old 12-09-12, 04:20 AM   #1
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 123
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()?
__________________
__________________
Aanson is offline   Reply With Quote
Old 12-09-12, 06:09 AM   #2
myrroddin
Premium Member
 
myrroddin's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 355
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
myrroddin is offline   Reply With Quote
Old 12-09-12, 06:11 AM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 525
http://facepunch.com/showthread.php?t=875909
__________________
The cataclysm broke the world ... and the pandas could not fix it!
Rilgamon is offline   Reply With Quote
Old 12-09-12, 08:55 AM   #4
Tuller
A Black Drake
 
Tuller's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 84
Generally, if I have an "array" and I care about ordering, I use ipairs. If I don't care, I use pairs.
Tuller is offline   Reply With Quote
Reply

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

Thread Tools
Display Modes

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