Lua Quick Start Guide
The easiest way to learn Lua programming
Gabor Szauer
- 202 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Lua Quick Start Guide
The easiest way to learn Lua programming
Gabor Szauer
About This Book
The easiest way to learn Lua programming
Key Features
- The easiest way to learn Lua coding
- Use the Lua standard libraries and debug Lua code
- Embed Lua as a scripting language using the Lua C API
Book Description
Lua is a small, powerful and extendable scripting/programming language that can be used for learning to program, and writing games and applications, or as an embedded scripting language. There are many popular commercial projects that allow you to modify or extend them through Lua scripting, and this book will get you ready for that. This book is the easiest way to learn Lua. It introduces you to the basics of Lua and helps you to 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 Lua, variables, data types, functions, tables, arrays and objects, is 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 in order to move onto other technologies such as Love2D or Roblox.
A quick start guide is a focused, shorter title that provides a faster paced introduction to a technology. It is designed for people who don't need all the details at this point in their learning curve. This presentation has been streamlined to concentrate on the things you really need to know.
What you will learn
- Understand the basics of programming the Lua language
- Understand how to use tables, the data structure that makes Lua so powerful
- Understand object-oriented programming in Lua using metatables
- Understand standard LUA libraries for math, file io, and more
- Manipulate string data using Lua
- Understand how to debug Lua applications quickly and effciently
- Understand how to embed Lua into applications with the Lua C API
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, as well as for beginner programmers who have never coded before.
Frequently asked questions
Information
Working with Lua
- Using variables
- Data types
- Working with functions
- Operators
- Code blocks
- Variable scope
- Code flow
Technical requirements
https://github.com/PacktPublishing/Lua-Quick-Start-Guide/tree/master/Chapter02
http://bit.ly/2LDVPd0
Variables
Creating variables
- Declare the variable
- Assign a value (data) to the variable
foo = "bar"
Printing variables
print (<variable>)
foo = "bar"
print (foo)
Assigning variables
color = "red"
print (color)
color = "green"
print (color)
color = "blue"
print (color)
Comments
foo = "bar"
-- print (foo)
-- The above statement never prints
-- because it is commented out.
Basic types
- nil: The absence of data. This type represents literal nothingness. If a certain piece of data is invalid or unknown, nil is usually the best way to represent that it is invalid or unknown.
- Boolean: A value of true or false. A Boolean value is binary and can only ever be in one of two states, true or false.
- number: A number can represent any real number: 0, -1, 5, or even decimals such as 3.14159265359.
- string: A string is an array of characters. When declaring a string literal, it must be "enclosed within quotation marks."
- function: A function is some code that is referred to by a name and can be executed any time.
- table: A table contains information using key-value pairs. Tables will be covered in depth in Chapter 3, Tables and Objects.
- userdata: Complex data structures defined in the C programming language.
- thread: Threads can be used to execute code in parallel. Instead of your code running one set of commands, it can run several sets of commands at the same time.