I started learning Prototype-based programming in Lua. I wonder what's the usage of metatables without metamethods. There is a line in example below self.__index = self when I remove this line somevalue is not visible in my new object this is normal because I didn't use the metamethod __index. What's the usage of metatables then - to use metamethods only? Sorry for trivial question but this is really interesting, I know I can use getmetatable to check the metatable of some object. I need simple answer: There is no usage without metamethods or there is(if yes then what).
-- Example taken from the official documentation.
Account = { somevalue = 1 }
function Account:new (o)
o = o or {} -- create object if user does not provide one
setmetatable(o, self)
--self.__index = self
return o
end
a = Account:new()
print(a.somevalue) -- nil, so I can't use any features of the metatable till I use some metamethod?