Chapter 2. First Steps
This chapter and the next two lay the foundation you need to understand the rest of the book. As such, they cover a great deal of material, although they're still very basic. If you've never programmed before, you'll learn a lot of new concepts; if you're an experienced programmer, you'll see a lot of things that you already know. In the latter case, you are encouraged to skim, but be warned: Some of the Lua building blocks covered in these three chapters may have no counterpart in the languages you are familiar with.
This chapter explains the:
Variables and assignment
true, false, and nil values
if statements and while, for, and repeat loops
Numbers and Arithmetic Operations: Basic Interpreter Usage
The Lua interpreter—
lua—is a program that can execute Lua code that you type right after you type it.
This is how the term interpreter is used in this chapter, but it can also refer to a particular internal component of the Lua implementation—more on this in the next chapter and Chapter 10.
In this section, you explore the basics of using
Addition, Subtraction, Multiplication, Division, and Exponentiation
Start with something simple—adding two and two. Access your system's shell, as described in Chapter 1. When you're there, type lua and press Enter (Return on some keyboards). You should see something like the following:
Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio >
lua starts the Lua interpreter. When it starts, it prints its ...