lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I'm confused by your confusion. The manual is totally clear and says everything you said in fewer words.

Undefined behavior means, in this case, adding a new key/value pair while traversing a table with `next` doesn't produce an error, but is incorrect because it may produce unpredictable results that are not defined by the language. There is nothing overly magical about it and the reason for this is self-evident tables are not guaranteed to be stable and `next` cannot know the context in which it is called.

It is true that Lua's reference manual is very sparse. I find myself needing to read it with extra care because it almost (?) never repeats itself. That's a style choice, but it isn't wrong and there's nothing missing in the description, as written.

On Thu, Jun 10, 2021 at 1:27 PM Viacheslav Usov <> wrote:
On Thu, Jun 10, 2021 at 7:16 PM Pierpaolo Bernardi <> wrote:

> This may be true for the implementation that you checked.
> What the language guarantees is: nothing.

This is illogical, because Lua is a versioned language, and each Lua
version is defined by the corresponding open-source implementation and
manual, modulo bugs.

For the record, the description I gave is based entirely on the manual
for Lua 5.4 (but either one could still have bugs).

It may also be correct for other versions of Lua, though.


Andrew Starks
612 840 2939