[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is it safe to modify values while traversing a table with lua_next()?
- From: Matthew Wild <mwild1@...>
- Date: Thu, 26 Jul 2012 13:02:13 +0100
On 26 July 2012 12:41, Carsten Fuchs <carsten.fuchs@cafu.de> wrote:
> Dear Lua list,
>
> using Lua 5.1, when I loop over the key-value pairs in a table using
> lua_next(), it is safe to modify the values?
> Especially if the new value is nil, in order to remove the key-value pair
> from the table?
>
> http://www.lua.org/manual/5.1/manual.html#lua_next explicitly warns about
> modifying the keys, but says nothing about modifying the values.
You can modify the values, including setting them to nil. The only
other thing you *can't* do is add new keys to the table. The
documentation for next() in the manual describes this a bit further.
Regards,
Matthew