lua

Lua is a programming language.

To be filled as I progress through December Adventure.

A table is a data structuring mechanism that is used for arrays, sets, queues. Tables are objects.

table = {a = 3, b = { c = 2 }}

print(table[a]) nil
print(table["a"]) 3
print(table.a) 3

print(table["b"]["c"]) 2
print(table.b.c) 2

k = "key"
table[k] = "value"

-- prints "value"
print(table["key"])
print(table[k])
print(table.k)

Functions and tables can be used to emulate OOP. TODO: read more about metatables

equality

print(10 == 10) true
print(10 ~= 11) true

Greater-/lesser-than (or equal to) operators work as usual, but an error will be thrown if a number is compared with another number in string form:

test = "9" >= 3
print(test)
attempt to compare number with string

logic

nil and false are false

The and operator returns the first argument if it’s false and the second otherwise. or is the opposite, returning the first argument if it is true.

print(nil and 1) nil
print(0 and 1) 1
print(0 or 1) 0
print(nil or 1) 1
print(false or nil) nil

concat

print("hello " .. "moon") hello moon
x = 0 .. 1
print(x) 01
print(type(x)) string

löve

LÖVE is a framework for making 2D games, using Lua.

Reload with lovelier:

pnpm i -g lovelier
lovelier dev .

resources