# lua
a lightweight embeddable scripting language. - Lua / online / Lua Guide
Pico-8
- it has some addition (
+=
,if() oneline
, ..)all
,add
- some which can be emulated on standard lua
-
it lack some standard fonction (
string.*
ntable.*
) which may exist (or not in a different form). - z8lua / github - a fork of Lua that implements the PICO-8 dialect.
- to install:
git clone
+make
=> z8lua binary - does not support
require
? as such difficult to use for unit-testing
- to install:
- Going from Lua 5.2 to PICO-8’s Lua
Lua Langage
Setup
$ sudo apt install lua5.2 # this is the closest to PICO-8 v0.2.5g
Table
Table can be treated as an array (list-like) or as a key-value dictionary.
-- Array
t = {1, 2, 3}
-- of dictionnary: Simple object-like table
Person = {
name = "Alice",
age = 25
}
Appending to a table
-- Array
table.insert(t, 4)
-- or assign to next index
t[#t + 1] = 5
for i, v in ipairs(t) do
print(i, v)
end
-- for dictionnary just assign the key
Person["c"] = 3
Person.d = 4 -- shorthand for t["d"]
for k, v in pairs(Person) do
print(k, v)
end
Object / Struct
see Meta-table
Operators Tutorial
Unit Testing
busted
The most widely used Lua test framework.
Syntax could be lighten with Moonscript. 🚧
Setup
$ sudo apt-get install luarocks
$ sudo apt install liblua5.2-dev # depending on lua -v
$ sudo luarocks install busted
$ busted --version # validate
Example
describe("math", function()
it("adds numbers correctly", function()
assert.is_equal(4, 2 + 2)
end)
end)
Then run with
$ busted . # By default, it looks for *_spec.lua files in your project.
VSCode 🚧
see Busted Test Explorer by Vivien Henriet
Busted error: spawn /usr/local/bin/busted ENOENT
Busted exited with code -2
see also
- LuaRocks - the package manager for Lua modules.
- Piccolo – A Stackless Lua Interpreter / HN
- Lux / HN - a luxurious package manager for Lua
Written on October 31, 2023, Last update on April 10, 2025
lua
lang
pico8
vscode