lua metatable bug or feature?

250 Views Asked by At

If I have this construct:

a.key = b

and both a has a metatable attached and b has a metatable attached. Then b's metatable setter will be called to set key to b. Is this a bug of lua 5.3.0?

EDIT: a and b are strings.

1

There are 1 best solutions below

4
user1095108 On BEST ANSWER

Tables and full userdata have individual metatables (although multiple tables and userdata can share their metatables). Values of all other types share one single metatable per type; that is, there is one single metatable for all numbers, one for all strings, etc. By default, a value has no metatable, but the string library sets a metatable for the string type (see §6.4).

Answer from the docs. It is a feature: a and b were string and hence shared their metatable.