Jump to content
Search

The new Ubuntu Wiki is live. Legacy content may be unavailable and page links may have changed. Read the announcement on Discourse.

Lua

From Ubuntu Wiki

Lua is a lightweight scripting language. It is commonly embedded in other software.

Examples of popular software that embed Lua include the Neovim text editor and the Defold game engine.

The Ubuntu wiki embeds Lua

This wiki includes Lua as a sandboxed scripting language using Scribunto.

There's a Lua script that generates nested, labelled boxes, for example:

Wiki
Sandbox
Lua

Install

To install version 5.5 of the Lua interpreter:

sudo apt install lua-5.5

When developing programs that use the Lua C API, you'll also need liblua.

sudo apt install liblua5.5-dev

REPL

Run lua with no arguments to start the interpreter:

$ lua

Lua 5.5.0  Copyright (C) 1994-2025 Lua.org, PUC-Rio
> print("hello world")
hello

Run a program

Create a hello.lua file and expand on the previous example:

local function greet(name)
  local msg = "Hello, " .. name .. "!"
  return msg
end

print(greet("world"))

To run the program:

lua hello.lua

Use Lua as a compile target

Some languages, notably Fennel, compile to Lua.

Fennel gives you Lua’s features and ecosystem while letting you write code in a Lisp-like syntax.

Read more on the Fennel page.