lua-users home
lua-l archive

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


On Sun, 17 Mar 2019 22:40:34 +0200
 Dirk Laurie <dirk.laurie@gmail.com> wrote:
Op So. 17 Mrt. 2019 om 18:25 het temp 213 qwe <temp213@gorodok.net> geskryf:

On Sun, 17 Mar 2019 12:42:32 -0300
Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> What problem does this proposal solve?

Absence of default metatables.

Since 'table' is Lua's only data structure, which does duty for
arrays, sets, dictionaries, lists, queues, stacks, XML encodings,
matrices etc, it would be quite annoying to find every table one
creates pre-equipped with a metatable that serves only one of these.

It affects only the tables WITHOUT a metatable, as soon as you setmetatable(), table would use it instead. If arrays, sets, dictionaries, lists, queues, stacks, XML encodings, matrices, etc do not set/change own metatable, it means that it do not use any metamethods either, except __index/__newindex. But yes, theoreticaly you could break the normal operation of other things by redefining __index, __newindex metamethods by default to something strange. And there is no need to set G(L)->mt[LUA_TTABLE] to {__index = table}, like it is done for the strings with {__index = string library}, G(L)->mt[LUA_TTABLE] could also be NULL by default, but see no disadvantage here, why not to make it for tables, if it was done like this for strings.