lua-users home
lua-l archive

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


We were surprised because 

self.__index=self
setmetatable(derived,self)

is so often written of as implementing inheritance, without caveat.    The reference manual is approximately the only place where it is noted that metamethod queries are raw.

I don't know when a new PIL is coming out but perhaps there's an opportunity in the treatment of OOP to show (and establish an idiomatic way of doing) what must be done to implement inheritance of __newindex, __call, and operators.  Overrides aren't clean without doing custom metatables.  We don't have to worry about that in our application but it means that setmetatable(derived,self) is not quite as universal as one would think.

-BSK

-----Original Message-----
From: Francisco Olarte <folarte@peoplecall.com> 
Sent: Saturday, March 28, 2020 1:08 AM
To: Lua mailing list <lua-l@lists.lua.org>
Subject: Re: Inheritance of metamethods in idiomatic Lua OOP--not as slick as one would expect

Bennet:

On Sat, Mar 28, 2020 at 7:28 AM Kalafut, Bennett <bennett.kalafut@thermofisher.com> wrote:
> We (Lua users at Thermo-Fisher) were surprised recently to find that the __index metamethod of the metatable’s metatable isn’t used when looking for things like __newindex metamethods.

Why were you surprised? The FM says "Lua queries metamethods in metatables using a raw access ".

I see you may have liked it other way, but IMO this part is clearly defined.

FOS