How to use a class's constructor on Lua

We add the following bits of code to our class:

setmetatable(MyClass, {  
  __call = function (cls, ...)
    return cls.new(...)
  end,
})

function MyClass.new(init)  
  local self = setmetatable({}, MyClass)
  self.value = init
  return self
end  

And now we can instanciate it easyly from outside of the class like so:

local instance = MyClass(5)  

From Lua documentation we can read the following:

Here we add a metatable to the class table that has the __call metamethod, which is triggered when a value is called like a function. We make it call the class's constructor, so you don't need the .new when creating instances. Another option would be to put the constructor right in the metamethod. In metamethods, "cls" refers to the current table.

source