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

Classes

A class is the template or blueprint that object instances are built from. A class defines variables and functions that every object made from that class is guaranteed to have. Each object, however, has its own copy of these variables, independent of each other.

For example, if we have a class to represent the enemies in a game, we can assume that each enemy has some health, an attack value, and some defense value. This is pretty easy to code up:

Enemy = { }Enemy.health = 200Enemy.attack = 4Enemy.defense = 20

This Enemy table will serve as the blueprint for all enemy objects. So, how can you create new objects from this blueprint? In OOP terms, a constructor is needed. A constructor is a function that instantiates a new object from ...

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