Language
Lua
- First appeared
- 1993
- Paradigm
- Imperative, scripting, multi-paradigm
- Toolchain
- Lua 5.4.7
- Container image
debian:trixie-20261027-slim + lua5.4 5.4.7-1+b2
Lua (Portuguese for “moon”) was created in 1993 at the Pontifical Catholic University of Rio de Janeiro by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. It was built to be embedded in larger programs, and it’s small and fast enough that it now runs inside game engines, Roblox, the Neovim editor, and network tools.
Lua has one data structure, the table. The same table type serves as an
array, a dictionary, a record, and an object, depending on which keys you
use. Arrays are tables whose keys are 1, 2, 3, and so on, and #t gives
their length. The standard library is small: string patterns, table.sort,
math, and file input and output. There’s no split, no round, and no CSV
reader, and modules from LuaRocks, Lua’s package manager, aren’t installed
here.
Quirks
- Indexes start at 1. With
a = {10, 20, 30},a[1]is 10 anda[0]isnil, not an error. 0and the empty string are true. Onlynilandfalseare false, so0 and "yes" or "no"gives “yes”./always gives a float, so10 / 2is5.0.//divides and rounds down:7 // 2is 3, and-7 // 2is −4.- Not equal is
~=, not!=. table.sortisn’t stable, so rows with equal keys can come out in any order. Its comparison must be a strict “less than”: sorting witha <= bcan stop with “invalid order function for sorting”.#is only reliable on an array with no gaps. Withh[1],h[2], andh[4]set,#hgave 4, althoughh[3]isnil.- Integers wrap around when they overflow:
math.maxinteger + 1ismath.mininteger. 1and1.0are the same table key, so settingd[1.0]overwritesd[1].
Concepts in Lua
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every Lua example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language lua