Chapter II · Idioms & deeper language / Lesson 10 of 27

Method syntax: : vs .

You'll learn: Read OO-style Lua and know when self is implicitly passed.

obj:method(args) is sugar for obj.method(obj, args) — the colon implicitly threads obj as the first argument. Use : when calling methods, and function T:foo(...) when declaring them. The two forms below produce the same bytecode.

method-syntax.lua
Output idle
Hit Run to execute.
Try it: Toggle Bytecode and compare the disassembly for the two hello calls.