lua-users home
lua-l archive

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


> >> >[...]
> >> >
> >> >for k,v in pairs(t) do
> >> >   t[k] = nil
> >> >   if (<some condition>) then
> >> >     t[k] =<some other value>
> >> >   end
> >> >end
> >> >
> >> >[...]
> 
> What's do you mean, "not formally allowed"?
> 
> "The behavior of next is undefined if, during the traversal, you
> assign any value to a non-existent field in the table. You may however
> modify existing fields. In particular, you may clear existing fields."
> - it's from Lua 5.1.4 reference manual.

See the code: When it does t[k] =<some other value>, the field t[k] does
not exist (it was erased two lines earlier), so it is assigning to a
non-existent field, which is explicitly forbiden.

-- Roberto