Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

You need two things for this course: a Python environment that runs the lab notebooks, and a standalone Lua 5.4 interpreter with LuaRocks, Lua’s package manager, for scripts and projects. Set up both before you start Module 1. The commands below are for Linux and macOS; on Windows, run them inside the Windows Subsystem for Linux (WSL).

Run every command from the root folder of the repository that holds the course, the folder with requirements.txt in it.

The notebook environment

The labs are Jupyter notebooks. Their %%lua cells use the Lua interpreter built into lupa, a Python package. The default is Lua 5.4.8. Labs that compile C code or launch a separate Lua process also use the standalone tools you install below.

  1. Install Python 3.12 and uv, a Python package installer.

  2. Create the environment and install the course’s packages:

    uv venv .venv --python 3.12
    VIRTUAL_ENV=.venv uv pip install -r requirements.txt

    The second command ends by listing the packages it installed.

  3. Start JupyterLab:

    .venv/bin/jupyter lab

    JupyterLab opens in your browser.

  4. Open courses/lua101/modules/01-first-steps/lab01.ipynb. Run the first code cell under Setup to load the extension and print the Python and lupa versions. Run the next code cell to see Lua 5.4.

Standalone Lua and LuaRocks

From module 1 you also run Lua scripts with the lua command, and from module 6 you install test tools with LuaRocks. hererocks, which the notebook environment installed, builds both into a folder of their own. It needs a C compiler: gcc or clang on Linux, and the Xcode Command Line Tools on macOS (xcode-select --install). On Linux it also needs the headers of GNU Readline, the library that lets you edit a line and recall earlier ones at the interactive lua prompt. Install them with sudo apt install libreadline-dev on Debian and Ubuntu, or sudo dnf install readline-devel on Fedora.

  1. Build Lua 5.4.8 and LuaRocks 3.13.0 into .venv/lua:

    .venv/bin/hererocks .venv/lua -l "https://github.com/lua/[email protected]" -r "https://github.com/luarocks/[email protected]"

    hererocks downloads both from GitHub, builds them, and ends with Done. The command names the releases from GitHub because hererocks’ own list of Lua versions stops at 5.4.4. Version 5.4.8 matches the language version in the notebooks. The standalone interpreter also supports operations the notebook disables, such as os.exit.

    If the build stops with readline/readline.h: No such file or directory, the readline headers are missing. Install them and run the command again, or add --no-readline to the end of the command. Without readline, scripts run the same, but the interactive prompt can’t edit a line or recall earlier ones.

  2. Put the new lua and luarocks commands first on your PATH for this terminal:

    source .venv/lua/bin/activate

    Run this again in each new terminal, or add the folder .venv/lua/bin to your PATH for good.

  3. Check the interpreter:

    lua -v

    It prints:

    Lua 5.4.8  Copyright (C) 1994-2025 Lua.org, PUC-Rio

A system Lua 5.4 interpreter works for the standalone language examples. For Lab 13, use the hererocks build above. Its C compiler commands look for the interpreter, headers, and static library under .venv/lua.

Tools for later modules

Install these when the module that uses them begins:

ToolModuleInstall
LPeg, the parsing library4luarocks install lpeg, which compiles it with the C compiler from step 1
busted, the test framework6luarocks install busted
luacheck, the linter, and LuaCov, the coverage tool11luarocks install luacheck and luarocks install luacov
StyLua, the formatter11cargo install stylua --locked --features lua54, or a release from StyLua’s GitHub page; a build without lua54 can’t read <close>
lua-language-server, the type checker11A release from lua-language-server’s site
A C compiler and the Lua headers13The compiler from step 1 above; hererocks already installed the headers in .venv/lua/include

The course’s examples were checked with LPeg 1.1.0, busted 2.3.0, luacheck 1.2.0, LuaCov 0.17.0, StyLua 2.6.0, and lua-language-server 3.19.2.