Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

The : operator

In the previous section, you implemented some object-oriented principles by building an enemy class, instantiating several enemies and calling some methods on the enemy instances. While all of the code was technically correct, each enemy instance had to be passed to the function stored in the enemy class.

Lua provides some syntactic sugar for calling functions on objects, the colon (:) operator.

This operator automatically provides the first argument to a function. This first argument, by convention, is called self. You can call this first argument whatever you want, but following convention will make your code easy to read and maintain.

The following bit of code demonstrates how the colon operator is used in comparison to ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content