[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: metatable for the registry?
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Mon, 19 Jul 2010 19:51:28 +0200
2010/7/19 Patrick Donnelly <batrick@batbytes.com>:
> On Mon, Jul 19, 2010 at 1:40 PM, Peter Cawley <lua@corsix.org> wrote:
>> On Mon, Jul 19, 2010 at 6:33 PM, Jerome Vuarand
>> <jerome.vuarand@gmail.com> wrote:
>>> 2010/7/19 Josh Haberman <jhaberman@gmail.com>:
>>>> Interestingly enough, I just ran into the opposite problem. It appears
>>>> that my __gc method isn't respected when I do the C equivalent of:
>>>>
>>>> setmetatable({}, {__index = {__gc = foo}})
>>>>
>>>> Lua only seems to find __gc when it is set directly on the metatable.
>>>> It doesn't find it via __index.
>>>
>>> Like all metamethods, __gc is not looked up by an index operation on
>>> the object itself, but by an index on its metatable. For the same
>>> reason the following doesn't work :
>>
>> I thought that all metamethods were looked up by rawget on the
>> metatable rather than index on the metatable.
>
> Right. That is what Jerome was saying? (He could have been more strict
> about his use of "index" though.)
Actually I didn't know, and was to lazy to check since it was
irrelevant to answer the OP (any way the metamethods are never
looked-up in the __index of the main object metatable). And I
shouldn't have answered at all since I realised later someone else did
(though for some reason it was not threaded properly by gmail).