Love2D dev : Create, edit, build and run Love2D applications with Sublime Text 3 (macOS)



How to install a lightweight development environment based on Love2D

If you intend to create / learn to code and develop games and other applications without having to use heavy tools, this article may be of use to you.

If you’re on macOS and are having trouble getting Sublime Text 3 to work with Love2D, these lines might be a timesaver, as it will save you some pitfalls regarding certain installation details on macOS.

The purpose of this tutorial is to introduce you to a way of building applications with a lightweight development environment, which only requires three main components :

  • Love2D : A framework that can be used to create applications in Lua language. It is mainly focused on video game development, but it allows you to create all types of applications. More info at https://love2d.org

  • Lua : A scripting language. In particular, this is a great language to learn to code. More info at https://www.lua.org

Here is a solution that allows to edit Lua code with Sublime Text 3 editor, and to build and run the result in a Love2D window.

Solution tested with Sublime Text 3 on MacOS Big Sur (having preliminary installed Lua via Brew, and Love2D via the official website : https://love2d.org).

To install Lua via Brew, type the following command line in the Terminal application :

brew install lua

https://formulae.brew.sh/formula/lua

https://brew.sh

To ease the integration of Lua and Love2D into Sublime Text 3, let’s install the following two Sublime Text packages :

  • Install the SublimeText Lua Love package :

Sublime Text Menu : Tools > Command Palette > Package Control: Install Package. Type “Lua Love”, select the relevant item to install the package.

https://packagecontrol.io/packages/Lua%20Love

  • Install the SublimeText PackageResourceViewer package :

Sublime Text Menu : Tools > Command Palette > Package Control: Install Package. Type “PackageResourceViewer”, select the relevant item to install the package.

https://packagecontrol.io/packages/PackageResourceViewer

The following setting on the SublimeText PackageResourceViewer package is necessary to be able to edit the SublimeText Lua Love package build system :

  • Sublime Text Menu : Sublime Text > Preferences > Package Settings > PackageResourceViewer > Settings – Default
  • Set “single_command” to true :
// Boolean setting specifying if a single command should be listed
// in the command palette for viewing and editing files or
// if multiple commands should be used.

"single_command": true,
  • Save. Now we are allowed to edit the SublimeText Lua Love package build system.

In order to be able to build and run your Lua code from Sublime Text in a Love2D window, let’s change the SublimeText “Love2D” build system part like so :

  • Sublime Text Menu : Tools > Command Palette > PackageResourceViewer : Edit Package Resource > Lua Love > LuaLove.sublime-build
  • Replace this part :
{
    "name": "Love2D",
    "shell": true,
    "cmd": ["love", "${project_path:.}"],
    "osx":
    {
	"cmd": ["love $project_path"]
    }
},
  • With this one :
{
    "name": "Love2D",
    "shell": true,
    "cmd": ["/Applications/love.app/Contents/MacOS/love", "$file_path"],
    "osx":
    {
        "cmd": ["/Applications/love.app/Contents/MacOS/love ${folder:${file_path}}"]
    }
},
  • Save.

Note : “/Applications/love.app/Contents/MacOS/love” corresponds to the path to the Love2D application for macOS. It might vary depending on your configuration.

Ok, Let’s test !

Now that everything seems to be in place, let’s see if things are going well :

  • In your Sublime Text 3 editor, open a main.lua file that is present in a .love folder.

For instance : a main.lua file in a MyCoolHelloWorld.love folder.

Here’s an example of minimum viable Love2D source code (to be placed in a main.lua file) :

io.stdout:setvbuf("no")

function love.draw()
    love.graphics.print("Hello World", 300, 300)
end

By default the console in Sublime Text will not display any output, such as print() calls, until the LOVE application has been closed. To make the console output display live add the following code to the top of your main.lua file, or inside conf.lua :

io.stdout:setvbuf("no")

Then do :

  • Sublime Text Menu > Build System > LuaLove
  • Sublime Text Menu > Build with… > LuaLove – Love2D

Then, the following times, you’ll just have to build like this :

  • Sublime Text Menu > Build

Normally, Sublime Text 3 will open the enclosing .love folder in a love2d window.

Enjoy, and happy coding !

Franck Mallouk – oniricforge.com

Related links :

https://love2d.org

https://love2d.org/wiki/Sublime_Text

https://love2d.org/wiki/Main_Page

https://love2d.org/forums/

Leave a Reply