lua-users home
lua-l archive

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




On 12/08/15 07:21 PM, Dirk Laurie wrote:
2015-08-12 22:56 GMT+02:00 Soni L. <fakedme@gmail.com>:
Currently:

t = setmetatable({}, setmetatable({}, {__index={__metatable="test"}}))
print(getmetatable(t) == debug.getmetatable(t))

Can we get getmetatable() to respect __index?
When is __index called? When some key in the original table is not
found. But when __index exists, then the metatable must exist too.
If getmetatable is to behave like an array access, then __index must
not be invoked.

Moreover, getmetatable does not return __metatable because
__metatable is a surrogate for the metatable. It is not that.
It is a lock, i.e. its presence  prevents access to the metatable.

Then how about adding a __getmetatable, so that we can properly proxy the string metatable?

(Really tho, it'd be nice if getmetatable() respected the metatable's metatable when accessing __metatable.)

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.