Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 103
    ah... so it's object-oriented syntactic sugar. Commented Feb 6, 2011 at 3:02
  • 18
    Exactly. In the entire reference manual, the only blurb they give on this is "The colon syntax is used for defining methods, that is, functions that have an implicit extra parameter self." (5.0 manual, bottom of pdf page 19) Commented Feb 6, 2011 at 3:24
  • 4
    ooh ahh... I was going to ask where the official docs were on this, but you beat me to it. nicely done. :-) Commented Feb 6, 2011 at 15:09
  • 1
    @keyle It depends on the self object will go as the first parameter and its properties value. Commented Feb 9, 2016 at 13:16
  • 12
    @keyle Colon syntax would be a little faster if the object you're calling is not a local, since the virtual machine retrieves it only once. Basically dot syntax like object.method(object,args) retrieves object twice, while object:method(arg) retrieves object only once. If object is a global, upvalue or table field, then : is faster than .. . is never faster than :. Commented Nov 5, 2016 at 8:08