0

I'm coming from Java and I just can't wrap my mind around why I see : and . used in what I would only use . for in Java.

For example I see this in Lua.

Person.doSomething() and then I see Person:GetName()

and in Java I would have only used the first option to execute a function. Am I just missing something basic here?

RBerteig
  • 41,948
  • 7
  • 88
  • 128
Max McKinney
  • 1,218
  • 15
  • 25

1 Answers1

2

Calling obj:Method(...) is literally identical to obj.Method(obj, ...), except that it only evaluates obj once.

Similarly, declaring function obj:Method(...) is identical to declaring function obj.Method(self, ...).

Basically, : is used whenever the function needs to have the concept of self.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347