Tools for Lua
A programming language relies heavily on the tools that support it. Lua files are plain text files. This means you can write Lua in any text editor you want, whether it is emacs, vi, Sublime Text, TextWrangler, or just the OS-provided basic text editor.
Because of the popularity of Lua, several IDEs, such as ZeroBrane Studio, Decoda, and LuaEdit, have been created for the language. An IDE is an integrated development environment. An IDE comes with everything you need to write, compile, and execute code. There are a number of advanced text editors that have varying levels of support for Lua:

Throughout this book, we will be using Visual Studio Code. VS Code is a free text editor, which supports the Lua syntax with its default installation and works across multiple platforms. The version of VS Code used is 1.9.1, but future versions should work more or less the same way.
Installing VS Code on Windows 10
Setting up VS Code for Windows is very straightforward. The installer takes care of everything for you. These instructions are written for Windows 10, but the process should be the same on all versions of Windows:
- Go to http://code.visualstudio.com/ and download the VS Code Code installer for Windows.
- Once downloaded, launch the installer exe file. The default options are all valid, so you can hit
Next
all the way through the installer. - Wait for the installer to finish the setup and exit the installer. There are no further actions to take.
Installing VS Code on macOS
These instructions are written for OSX High Sierra, but the installation steps should be the same on all supported versions of OSX:
- Go to http://code.visualstudio.com/ and download VS Code for macOS. This will download a zipped file named
VSCode-darwin-stable.zip
. - Double-click the zip file to extract its contents. Drag the resulting
Visual Studio Code.app
file into yourApplications
directory. - Once
Visual Studio Code
is in the Applications directory, it is installed, and there are no further actions to take.
Installing VS Code on Linux
These instructions are written for Ubuntu Linux 16.04. The steps needed to install Lua are the same for Ubuntu Linux 12.04 and higher.
- Go to http://code.visualstudio.com/ and download the Visual Studio Code installer
.deb
file. Take note of the name of the downloaded file; the version I am using is namedcode_1.9.1-1486597190_amd64.deb
. - Once downloaded, launch a new Terminal window. Navigate the Terminal to the
downloads
folder with the following command:cd ~/Downloads
. - Next, install the
.deb
file with the following command:sudo dpkg -i ./code_1.9.1-1486597190_amd64.deb
. The filename might be different based on the version of VS Code you downloaded. - Fix any missing or broken dependencies with the following command:
sudo apt-get install -f
. - Visual Studio Code is now installed, and there are no further actions to take.
Exploring VS Code
It's important to be familiar with the tools you use. While Visual Studio Code is primarily a text editor, it does boast a rather large set of IDE-like features. VS Code can easily become overwhelming if you are not familiar with using it.
Note
Visual Studio Code is a powerful text editor with many advanced features. If you are interested in learning more about the editor than this section covers, visit the online basics guide at https://code.visualstudio.com/docs/editor/codebasics.
Follow these steps to gain some familiarity and intuition with Visual Studio Code:
- When you open up Visual Studio Code, you are greeted with either the last open documents, the welcome page, or if you have no documents open and the welcome page is disabled, the default window.
- The icons on the left side of the screen make up what is called the View bar. Clicking any of the items on the View bar will cause a side bar to become visible:

- The first item on the View bar is the
Explorer
. You can use the Explorer to open a folder and View all of the files in that folder in one convenient list. We will use this feature of the editor throughout the next few chapters:

- The search item on the bar will let you search for and replace text in either open documents, or documents inside of the currently open folder.
- The
GIT
item on the View bar will only be available if the currently open folder is a git repository. VS Code has excellent git integration! While source control solutions such as git are outside the scope of this book, using some kind of source control is highly recommended:

- The
DEBUG
sidebar gives VS Code IDE features such as break points and a watch window:

- Finally, the
EXTENSIONS
item will show you a side bar that can be used to View, manage, and install new extensions in Visual Studio Code:

- To make a new file, simply select
File
>New File
. - This opens a new file, in a new tab. This file has no syntax highlighting yet. To assign a syntax, click on the
Plain Text
label in the bottom-right of the code tab, then selectLua (lua)
from the drop-down menu that appears:

- If at any point you open a file and it does not have proper syntax highlighting, you can follow the previous step to force the file to have Lua syntax highlighting. In the previous step, we set the syntax of the file manually. If you save a file with a
.lua
extension, the next time the file is opened, it will automatically use Lua syntax highlighting.