[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: metatable for the registry?
- From: Peter Cawley <lua@...>
- Date: Mon, 19 Jul 2010 18:40:28 +0100
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.