lua-users home
lua-l archive

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


I am traversing a table with next() every x seconds. Something like:

t = { ["a"] = true, ["b"] = true, ["c"] = true }

From time to time the table will be modified. The manual says:

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.

So if I say

t.b = false

it will traverse over a, b and c still (order doesn't matter to me).

If I say

t.b = nil

it will traverse over a and c still without problem.

But if I say

t.d = true

... the behaviour is undefined. Does this just mean it may or may not include t.d during the current traversal? I can live with that. Or would it produce an error?

Thanks!

Vaughan