Chapter I · Language basics / Lesson 5 of 27

Tables are everything

You'll learn: Build arrays, records, and nested tables, and know what #t actually counts.

Tables are *the* data structure: arrays, hash maps, records, modules — all tables. Indexed from 1 by convention. #t is defined for *sequences* ({v1, v2, ..., vn} with no nils) and unspecified for sparse tables. Mix array and hash keys in one literal.

tables.lua
Output idle
Hit Run to execute.
Try it: Add user.prefs.shortcuts = { save = "⌘S" } and print user.prefs.shortcuts.save. Then add user[5] = "trailing" — what does #user return now?