I am having a little hard time to understand the colon operator in lua. So I did some experiment on colon operator and came up with this conclusion.
class = {}
function class:me()
end
is equal to
function class.me(self)
end
Am I making a right conclusion?
If not, what is the problem?
Your conclusion is correct.
The : form is just syntactic sugar for the . form with self as the first parameter. This is documented:
The colon syntax is used for defining methods, that is, functions that have an implicit extra parameter self. Thus, the statement
function t.a.b.c:f (params) body endis syntactic sugar for
t.a.b.c.f = function (self, params) body end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With