lua-users home
lua-l archive

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


> Message: 6
> Date: Mon, 23 Dec 2013 17:22:30 -0500
> From: Rena <hyperhacker@gmail.com>
> Subject: Metatables cannot have metatables?
> To: Lua mailing list <lua-l@lists.lua.org>
> Message-ID:
> 	<CA+rfA1Q_Q5dEMsoi6q+t1W5RfmayoJgGNs0=oeMj747pw0UQ6w@mail.gmail.c
> om>
> Content-Type: text/plain; charset="iso-8859-1"
>
> I don't understand why this isn't working: http://pastebin.com/kGX5Eay0
> When asking for #t, it should check the metatable "meta" for a __len
> method. But this doesn't seem to invoke "meta"'s __index metamethod.
>
> -- =

Lua checks metamethods using raw accesses of the metatable, not via the __index mechanism you use to access methods like your '.foo'. Think about it: if this were not true, how would __index itself ever be found?

The metatable can still have its own metatable and you can use this to implement method inheritance, but you need to copy metamethods into the immediate metatable for them to take effect.

- John


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com