Re: Explicitly warn about lua_next missing an order guarantee in the reference manual
'Lars Müller' via lua-l <[email protected]>
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
As said, this bug often does not surface because most lists live in the
array part, as they ideally should. (I originally said tables, should
have said lists to be precise.)
But if you populate a table in a nonstandard order, or using the right
table constructor syntax, you /will/ get lists that partially or fully
live in the hash part.
For example, see what happens when you iterate the table {[1] = 1, [2]
= 2, [3] = 3}
using pairs() on PUC Lua (if you get the expected order, maybe retry a
few times, or add more entries).
For the same reason we tell Lua programmers not to expect pairs() to
iterate a table in order,
we should tell C programmers not to expect lua_next() to iterate a
table in order.
And as said, I think that it would be highly beneficial if a sentence
or two to that effect
were added to the section on lua_next() in the reference manual.
So I hope one of the Lua authors sees this and updates it.
- Lars
On Thu, Apr 16 2026 at 00:00:47 +00:00:00, 'Sainan' via lua-l
<[email protected]> wrote:
>> The order in which the indices are enumerated is not specified,
>> even for numeric indices.
>
> Well, the order is guaranteed for numeric indecies, as long as those
> numeric indecies start at 1 and increment from there. :^)
>
> -- Sainan
>
> --
> You received this message because you are subscribed to the Google
> Groups "lua-l" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to [email protected]
> <mailto:[email protected]>.
> To view this discussion visit
> <https://groups.google.com/d/msgid/lua-l/z2n0lQNJMcdKCs-h5cMV__eyE2tlgKPNxj_wU2jRgQPs5KEdGTVusWTRIU-kTpQvMnVj07A4wng9WZX9oO3kXnSVGNnv_KwlLZbaEqAeeL8%3D%40calamity.inc>.
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/E3GLDT.NMD9JJGV5D5D2%40gmx.de.