lua-users home
lua-l archive

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


On 17.03.2018 07:32, Philipp Janda wrote:
Am 16.03.2018 um 12:31 schröbte Dirk Laurie:
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.

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.
I don't see how this is a problem, as long as you need to need to set the mode of the table explicitly. Therefore this is surely new code, and of there is a leak in it, it is a mistake not a backwards compatibility problem. Of course you may not pass a strong table to old libraries.
If you want to write backwards compatible code, just don't use the feature at all or make a version check.
--
Thomas