Re: Table enumeration
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Table enumeration
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: 2020年10月28日 21:59:44 -0300
> Another way to put it: does pairs() always enumerate first what would be
> enumerated by ipairs(), then the rest of the table?
No. Although lua_next does traverse the array part first, there may be
entries for the list part in the hash part. Here is an example. You
may have to run it a few times to see this.
% cat a
a={10,20}
a.foo="bar"
a[5]=50
a[4]=40
a[3]=30
for k,v in pairs(a) do print(k,v) end
% lua -v a
Lua 5.4.0 Copyright (C) 1994-2020 Lua.org, PUC-Rio
1 10
2 20
3 30
4 40
foo bar
5 50