[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strong tables in Lua 5.4
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 16 Mar 2018 13:34:42 +0200
2018-03-16 13:31 GMT+02:00 Dirk Laurie <dirk.laurie@gmail.com>:
> 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.
On second thought, that function must not be supplied. Really removing
a key from a strong table should be not be made easy. The user can
write that function if foolhardy enough.