Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Valuable variables

Like in many scripting languages, Lua has variables. You can think of it as something that stores values. When you apply a value to a variable, you can refer to it using the same variable.

An application consists of statements and variables. Statements provide instructions on what operations and computations need to be done. Variables store the values of these computations. Setting a value into a variable is called an assignment.

Lua uses three kinds of variables: global, local, and table fields.

Global variables

A global variable can be accessed in every scope and can be modified from anywhere. The term scope is used to describe the area in which a set of variables live. You don't have to declare a global variable. It is created as soon as you assign a value to it.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial