Here is the link to the tutorial where I got the following example. Here is the script:
local MyClass = {}
MyClass.__index = MyClass
setmetatable(MyClass, {
__call = function (cls, ...)
return cls.new(...)
end,
})
function MyClass.new(init)
local self = setmetatable({}, MyClass)
self.value = init
return self
end
-- the : syntax here causes a "self" arg to be implicitly added before any other args
function MyClass:set_value(newval)
self.value = newval
end
function MyClass:get_value()
return self.value
end
local instance = MyClass(5)
-- do stuff with instance...
I understand the first example in the tutorial to which I provided a link. The main question I have is about line 5 above. How does the __call function work and what is its purpose. I would be really grateful if someone could help me understand this. Thanks!

3 comments
There is a full list of all the metamethods and all the definitions of them here.
That does not help me understand what it is doing.
Just what __call does