Lua中ipair和pair的区别
先看看官方手册的说明吧:
pairs(t)Ifthasametamethod__pairs,callsitwithtasargumentandreturnsthefirstthreeresultsfromthecall.
Otherwise,returnsthreevalues:thenextfunction,thetablet,andnil,sothattheconstruction
fork,vinpairs(t)dobodyend
williterateoverallkey–valuepairsoftablet.
Seefunctionnextforthecaveatsofmodifyingthetableduringitstraversal.
ipairs(t)Ifthasametamethod__ipairs,callsitwithtasargumentandreturnsthefirstthreeresultsfromthecall. Otherwise,returnsthreevalues:aniteratorfunction,thetablet,and0,sothattheconstruction fori,vinipairs(t)dobodyend williterateoverthepairs(1,t[1]),(2,t[2]),...,uptothefirstintegerkeyabsentfromthetable.