Since Lua is very much a batteries-not-included solution when it comes to “real” OOP, it would be interesting to hear from folks who had adopted some ad-hoc standard (or even non-standard) coding approach for it. I’ve had a look through the norns apps and while a lot of them use object libraries, none seems to implement objects over and above simple encapsulation of values and functions into tables.
I’m pretty much following the pattern for inheritance from the official programming guide here, including the explicit-self-as-metatable trick which enables inheritance, although so far monkey-patching new methods is tidier than attempting inheritance in this manner. Also, I notice that this mechanism only works for default values which are scalar, since there’s a reliance on
__index to lift it by copying from the prototype, which feels a bit fragile.
Lua programs I’ve seen in the wild seem to come down 50-50 in favour of
Class:new(); the latter is needed for sub-classes to get the metatable in the right place for inheritance to work.