lua-users home
lua-l archive

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


Leandro Pelorosso wrote:
> Indeed, but, don't you know what kind of undefined
> behavior can i get?. (maybe something like iterate
> elements that i already visit, or something like that)

Undefined is undefined. You could get repeat elements,
you could miss elements, you could get an error. About
all you can say is that it won't crash.

Your best bet is to add the new elements to another
table and then merge them afterwards:

do
  local newstuff = {}
  for k, v in pairs(tab) do
    -- whatever
    if some_condition then
      newstuff[newkey] = newval
    end
  end

  for k, v in pairs(newstuff) do
    tab[k] = v
  end
end