[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Inheritance of metamethods in idiomatic Lua OOP--not as slick as one would expect
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Sat, 28 Mar 2020 22:02:20 +0000
On Sat, 28 Mar 2020 at 06:28, Kalafut, Bennett
<bennett.kalafut@thermofisher.com> wrote:
> Maybe the performance hit for always respecting the metatable’s metatable is too great?
I believe it is. It might also be prone to infinite recursion. But
keep in mind that if you embed Lua in your app, all your desires are
just a small patch away.
The more fundamental thing I'd question is whether there really is any
idiomatic Lua OOP, beyond the object:field() method call syntax.
"mt.__index = mt" shortcut is fine for a handful of usertypes in a
single file script (if you use it to shave the table allocs you
probably got bigger problems). Beyond simple scripts you probably need
something more elaborate. I'd argue that properties/getters get
desirable way earlier than inheritance, and as soon as you need these
all your __index-es become functions anyway.