Soo today when working with OOP i observed very strange behavior, it happens when we have nested metatable, for instance:
Class Creator → Class → Object
Note: Class Creator is module that creates classes and have some shared methoods like constructor or metatables
When it happens
The strange thing happens when you try to call methamethood inside Class Creator from Object, if we write:
print(Object.SomeIndex)
If there is __index methamethood inside Class Creator it will fire normally, but let say we have __add metamethood inside Class Creator and we call it from Object
print(Object + {1, 2, 3})
It will throw an error, as if metamethood won’t fire
Note: Class have table cycle reference, soo object inherits all of class’s methoods, when class’s metatable is Class Creator
Question is, if __index metamethood is recursive, this mean if let’s say Object don’t find index, it searches through Class, but if Class have metatable, it searches through it too?