How can I safely iterate a lua table while keys are being removed

前端 未结 2 1056
花落未央
花落未央 2021-01-11 23:01

In my main coroutine, I am removing or adding entries from a table depending on user operations. In the background, I\'d like to iterate over the entries in the table. I don

2条回答
  •  灰色年华
    2021-01-11 23:19

    You can safely remove entries while traversing a table but you cannot create new entries, that is, new keys. You can modify the values of existing entries, though. (Removing an entry being a special case of that rule.)

提交回复
热议问题