Continuing the discussion from What does .__index do?:
So I am currently learning OOP, and in the last reply of the above post, the commenter shows an example of chaining .__index commands together. I was wondering how it would look in an alternate format (the one used in this All about Object Oriented Programming)
ClassA = {}
ClassA.__index = ClassA
function ClassA.new()
local ClassB = {}
ClassB.__index = ClassB
setmetatable(ClassB, ClassA)
function ClassB.new()
local ClassC = {}
setmetatable(ClassC, Class
end
end
Is this how chaining .__index would look in one script?
From what I understand: Basically ClassC’s .__index is ClassB, which ClassB’s .__index is ClassA. So if I called a function in ClassC that doesn’t exist via the metatable it will check ClassB for the function using .__index, and then via ClassB’s metatable it will check ClassA using .__index.