Lua Quick Start Guide
The easiest way to learn Lua programming
Gabor Szauer
BIRMINGHAM - MUMBAI
Lua Quick Start Guide
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Noyonika Das
Content Development Editor: Roshan Kumar
Technical Editor: Sushmeeta Jena
Copy Editor: Safis Editing
Project Coordinator: Hardik Bhinde
Proofreader: Safis Editing
Indexer: Aishwarya Gangawane
Graphics: Jason Monteiro
Production Coordinator: Shantanu Zagade
First published: July 2018
Production reference: 1250718
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78934-322-9
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Gabor Szauer graduated from Full Sail University with a bachelor's degree in game development. He has been making video games professionally since 2010. He has worked on games for the Nintendo 3DS, Xbox 360, browser-based games, as well as games for iOS and Android. Gabor loves to teach, especially game development and programming. He has previously written the Game Physics Cookbook and is looking forward to producing much more content for those who want to learn.
"Give someone a program, you frustrate them for a day; teach them how to program, you frustrate them for a lifetime."
- David Leinweber
About the reviewer
Jayant Varma is an author of books on iOS development (Swift, Objective-C, and Xcode); Bash & Lua was his first book. He has been the technical editor for several Packt books. An academician at JCU, he mentored students for the Apple Swift Course at RMIT. He was the IT manager for BMW & Nissan, and as a development manager for an ASX-listed company, he contracted and built several mobile apps for small-to-large organizations in Australia. He has conducted workshops and spoken at meetups and events. He started OZApps and provides consulting and development services.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
Lua is a small, powerful, and extendable programming language that can be used to learn to program, write games and applications, or as an embedded scripting language. This book is the easiest way to learn Lua; it introduces you to the basics of Lua and helps you understand the problems it solves.
You will work with the basic language features, the libraries Lua provides, and powerful topics such as object-oriented programming. Every aspect of programming in Luavariables, data types, functions, tables, arrays and objectsis covered in sufficient detail for you to get started. You will also find out about Lua's module system and how to interface with the operating system.
After reading this book, you will be ready to use Lua as a programming language to write code that can interface with the operating system, automate tasks, make playable games, and much more. This book is a solid starting point for those who want to learn Lua and then move on to other technologies, such as Love2D, to make games.
Who this book is for
This book is for developers who want to get up and running with Lua. This book is ideal for programmers who want to learn to embed Lua in their own applications, and is also ideal for beginner programmers who have never coded before. Starting with an introduction to the Lua language, you will learn how to create variables and use loops and functions. You will learn advanced concepts, such as creating an object-oriented class system using only Lua tables. We look at the standard Lua libraries and learn how to debug Lua code. We will use Lua as an embedded scripting language and learn about the Lua C API in detail.
What this book covers
, Introduction to Lua, serves as an introduction to Lua by answering the question what is Lua? Next, the chapter walks the reader through downloading and installing the appropriate Lua binaries, as well as Visual Studio Code. Visual Studio Code is the code editor we will be using throughout this book to edit Lua files.
, Working with Lua, is a primer on the basics of the Lua language. For those who have not programmed before, this chapter teaches the basic concepts of programming, such as variables, loops, and functions. For the more experienced programmer reading the book, this chapter serves as an introduction to Lua's syntax.
, Tables and Objects, states that the most powerful features of Lua are its table and meta-table systems. Through these systems, the language it self can be extended. This chapter focuses on exploring what tables are, how they work, and how they can be used to extend the language to support concepts such as object-oriented programming.