lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Jun 7, 2019 at 10:26 AM Xavier Wang wrote:

It should be x = a.MyClass(a, b), and makes an error (because there is no MyClass in a), the correct way to write it:
local x = (a:MyClass)(b:MyAnotherClass)
It's just like "foo":format() is an error, you must write ("foo"):format()
and, you want call a as a function? why you need type annotation in this case?



 Because it's a common practice to construct a new instance by invoking its class having __call metamethod.
   local inst = Class()
is often the same as
   local inst = Class.new()