lua 元表错误或功能?
lua metatable bug or feature?
如果我有这个构造:
a.key = b
并且 a 和 b 都附加了元表。然后调用b的metatablesetter设置key为b。这是 lua 5.3.0 的错误吗?
编辑:a 和 b 是字符串。
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).
文档中的答案。这是一个特性:a 和 b 是字符串,因此共享它们的元表。
如果我有这个构造:
a.key = b
并且 a 和 b 都附加了元表。然后调用b的metatablesetter设置key为b。这是 lua 5.3.0 的错误吗?
编辑:a 和 b 是字符串。
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).
文档中的答案。这是一个特性:a 和 b 是字符串,因此共享它们的元表。