lua-users home
lua-l archive

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


On Tue, Nov 24, 2020 at 12:51 AM Sean Conner wrote:
   game_field = {} -- AN EMPTY TABLE

Ok, you have found two workarounds:
1) creating a new array instead of reusing the old one
2) using false instead of nil

But how would a user know that he needs to use a workaround in this situation?
AFAIK neither reusing tables nor using nils is discouraged in Lua.

(Using nils is not recommended only when you want to use the length operator.
But in my example the length of the array is known in advance, so no need to use "#")

I agree that adding the following line to the Lua manual would be a very non-elegant, but acceptable solution to the problem:
"Assignment of nil to a non-existing key in a table should be avoided, for performance reason."
Having this claimed explicitly, it would be a user's responsibility to find the most suitable workaround.