I am having difficulties with Lua's inheritance. I am getting an error
"Error: main.lua:32: attempt to call field 'String' (a nil value)"
What am I misunderstanding ? I don't understand how my example differs from : https://www.lua.org/pil/16.2.html
Animal = {}
function Animal:New()
a = {}
setmetatable(a,Animal)
a.__index = Animal
return a
end
function Animal:String()
print("I am an animal")
end
Cat = {}
function Cat:New()
c = Animal:New()
setmetatable(c,Cat) -- Set metatable to be Cat
c.__index = Animal -- Inherits from Animal
return c
end
-- Overwriting Bark
function Cat:String()
print("I am a cat")
end
c = Cat:New() -- Should return a cat
print(c:String())