notes

Lua

I love Lua. After years of writing Javascript I was getting frustrated with its English-like polyglot throw-everything-in with the bathwater (es5), change how parts of the code work (var vs let), and disable previously working parts (sound, vui, video), and constantly build new dev tools that supersede the old (electron/npm, etc). Well…all of those things disappear with Lua, but it retains the things I DO like.

I love glue languages and ‘scripting’ languages. I like that Lua is lightweight. I love that it’s syncronous. It’s fast. It’s extremely cross-platform. Even very old versions run fine, and a book I have on Lua from 2005 was still 99% useful for learning the language.

The downside is that there are many less resources and packages. The upside is that even very old GitHub repos or tutorials or online materials still work no problem, since the language is so robust and slow-to-be changed. I also grew to love its simplicity in the form of “tables”. Finally, I love that to make 2d works there is the excellent somewhat Processing-like Love2d library, which provides so much functionality.

With a quick overview of the language you can start using it right away. I find Lua programs very readable.

Compared to python, there are way less ‘batteries’ and functions to use. Where something in python might be a function call, in Lua you’ll have to build in the needed mechanism for it. For example, in Python, if you have a list like myList = [1, 2, 3, 4] you can just print that out like print(myList). That is not built into Lua. See the first useful snippet below for how to reproduce that functionality.

For additional utilities not included in Lua there is a package manager Luarocks. It is not nearly as extensive as npm or the various python (pip, pip3, pypi?) equivalents but it is still useful.

Game engines

Lua has been adopted by a number of game platforms and engine’s so that users can make mods. As well, you can code a game from scratch in Lua-based code editors.

Pico-8 is a tremendous fantasy console with over a decade of history and tens of thousands of games, an online BBS where users share games and code. It is not free and open source, but it is very affordable, and has lots of support and beginner-friendly resources. The Pico-8 system includes a code editor, sprite editor, map editor, sound editor, pattern editor, and an online game browser splore.

LÖVE aka Love2d is a free and open source 2d game framework. It’s been around since 2008 and has a large community built around it. It’s especially great for rapid game-making like game jams.

Tic-80 is a free and open source fantasy console inspired by Pico-8. I haven’t used it, but it has similar affordances with limited palette, built in code editor, sprite editor, map editor and a command line.

Picotron is the latest creation of Zep, the creator of Pico-8. It is a fantasy workstation meant to emulate a retro-style console like a computer. You code programs, system software and the like with Lua. It is in early alpha.

Roblox is a proprietary game ecosystem, but could be fun to hack on as you can make social 3d games in a modified version of Lua called Luau.

Playdate is a hardware handheld game system, like a modern Gameboy. Games can be programmed in a Lua SDK that appears similar in parts to Love2d or Pico-8.

Batteries - a library of many added functions, many for use by but not only for Love2d. There is also a useful repo of examples.

LuaRocks - The package manager for Lua modules.

Lua, the official website of the language. There is also a free web-based series of books, also available in print, from the developers of the language.

Is Lua Worth Learning? is a brief introductory article from OpenSource.com. Its author Seth Kenlon is also the author of Developing Games on the Raspberry Pi: App Programming with Lua and LÖVE, which I thought was a great introduction to making games, and doesn’t really need to be used in conjunction with a Pi since it’s primarily a good extended book on how to make a variety of 2d and puzzle games from card games to a simple roguelike.

Processing to Love, a tutorial I wrote on transitioning from Processing and p5.js to Love. Written primarily for those interested in and coming from a background in creative coding.

Useful snippets

Dump out a table

function dumpTable(tbl, indent)
    indent = indent or 0
    for k, v in pairs(tbl) do
        print(string.rep(" ", indent) .. tostring(k) .. ":")
        if type(v) == "table" then
            dumpTable(v, indent + 2)
        else
            print(string.rep(" ", indent + 2) .. tostring(v))
        end
    end
end

-- Example usage
myTable = {a = 1, b = {c = 2, d = 3}, e = 4}
dumpTable(myTable)