- Getting Started with Lua + LÖVE: Part 1 (Building, Installing, and Testing)
- Getting Started with Lua + LÖVE: Part 2 (Loading, Updating, and Drawing)
- Getting Started with Lua + LÖVE: Part 3 (Basic Physics)
- Getting Started with Lua + LÖVE: Part 4 (Using Images)
- Getting Started with Lua + LÖVE: Part 5 (Object-Oriented)
Notes on this guide:
This guide is written for a broad audience.
For those wanting to use Lua + LÖVE on the command-line, the steps of building and installing them will be enough. Once installed and configured, games can be coded using any number of text editors.
For those who want to use an IDE, skip down to using the ZeroBrane Studio, a integrated IDE for writing projects in Lua. It understands LÖVE games and can be used to easily test and build projects from inside the IDE itself.
Lua (LOO-ah) is an open-source, embedded scripting language. Commonly found as part of other, larger programs as its scripting system, Lua is often the most popular scripting languages in games and their engines.
LÖVE is an open-source 2D framework for creating games in Lua.
(Optionally) Manually Installing Lua
Lua can often be found pre-installed on many Linux and MacOS-based systems. Testing in a terminal window with “lua -v” can determined if it exists.
Building and installing in a Linux system (with curl also installed) is as follows:
curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz tar zxf lua-5.3.4.tar.gz cd lua-5.3.4 make linux test make linux install
Building and installing in a MacOS X system (with curl also installed) is as follows:
curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz tar zxf lua-5.3.4.tar.gz cd lua-5.3.4 make macos test make macos install
Note: Additional instructions for manually building and installing Lua in Windows can be found here.
(Optionally) Manually Installing LÖVE
Like Lua, LÖVE can also optionally be manually installed through different packages from its homepage.
Installing ZeroBrane Studio
For those wanting to use an IDE, ZeroBrane Studio is highly recommended for its integration with both Lua and LÖVE projects.
Installing ZeroBrane Studio is as easy as downloading the appropriate packages from the website.
Note: On most systems, installing ZeroBrane Studio will also install both Lua and LÖVE libraries.
Basic LÖVE Example
Once Lua + LÖVE has been installed through either manually building a copy or simply using ZeroBrane Studio, it is time to test it.
Preparing a New Project in ZeroBrane Studio
To start a new project in ZeroBrane Studio, go to Project –> Project Directory and then “Choose…”. Create or pick a new folder. This will be the project directory and ZeroBrane Studio will look here first for files to include.
Once a new project directory is selected, go to Project –> Lua Interpreter and select “LÖVE” is not already chosen. This is will let ZeroBrane Studio to use LÖVE.
Creating a main.lua file
Using either the command-line or ZeroBrane Studio (File –> New) create a new file. This will serve as the example.
Copy the following code.
Via GitHub Gist:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|love.graphics.print("Hello World!", 400, 300)|
function love.load() end function love.update() end function love.draw() love.graphics.print("Hello World!", 400, 300) end
Save this file as “main.lua”. (In ZeroBrane Studio, File –> Save or Command-S keyboard shortcut.)
To run on the command-line, assuming the current working directory contains the file, type “love ./” to run the file. (LÖVE works on directories, not single files.)
In ZeroBrane Studio, click on the green “Run” button on the tool menu or press F5.
If everything has been configured correctly, the screen will show “Hello World!” once run.