|
Am 16.03.2018 um 12:31 schröbte Dirk Laurie:This would make code that is always wrong (leaks table keys) in 5.4work1 only sometimes wrong with "strong" tables. I'm not sure that is better, because you'd have to fix it either way, and you would have less pressure to do so.
Define a "strong table" as one in which 't[k]=nil' does not remove the
key, it stores nil.
In Lua 5.4 (work1), all or no tables are strong, depending on
LUA_NILINTABLE. A new keyword 'undef' is needed to remove a key from a
strong table.
If instead of that, a hitherto unused letter of the __mode metafield
(say 'n') is used to indicate whether a table is strong, then
(a) strong and non-strong tables could coexist in the same code;
(b) no compiler variable would be needed
To remove a key from a strong table, a function table.undef could be
supplied that temporarily replaces 'n' in __mode by a neutral letter
and does a rawset.
I think that storing nils in tables is worth a break in backwards compatibility. We should just call it Lua 6.0 and design a nicer syntax for deleting keys.
Philipp