lua-users home
lua-l archive

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


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.)

-- 
- Patrick Donnelly