lua-users home
lua-l archive

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



On Thu, Mar 15, 2018 at 11:56 AM,  wrote:

Wouldn't it be prudent to make this behaviour (storing nils in tables) optional and control it per table using the mode field? Maybe even separately for array and hash part. Then, get rid of undef, which is already confusing people, and instead use table.remove to get really rid of table entries. table.remove would then obviously have to accept ather key types than integers. This could be complemented with a function to remove all entries of a table with integer keys larger than some value.

I think this would be a lot easier to explain, like, "if you want to store nils in tables, set the tables' __mode metafield to include 'y', and bob's your uncle". Also, it would be backwards compatible.



Good solution!
__mode metafield containing "n" character (#, next, pairs, ipairs must respect it) and function table.delete(tbl, key)
"n" because of "nil in table"