Lesson 25 of 55
9 mins readPython Tables: The Universal Data Structure
In Plain English
In Lua, the `table` is the only data structuring mechanism. Tables represent arrays, dictionaries, sets, records, and objects all in one unified, highly optimized structure.
Deep Dive: How It Works
Table Constructor: `{}` creates a new, empty table in heap memory.
Pass by Reference: Tables are objects; assigning a table variable copies the memory reference, not the underlying contents.
Hybrid Storage: Lua virtual machine implements tables internally as a combined contiguous array part and hash table part.
Core Rules to Remember

Sole Data Structure: Tables power arrays, dictionaries, namespaces, modules, and OOP.

Reference Semantics: `a = {}` and `b = a` both point to the exact same table.
Live Interactive Example
Hit Run Code to see it liveCreating and Referencing Tables
Python 3.12
1
2
3
4
5
6
7
8
Output Console
Click "Run Code" to view the rendered output.
How it works: Modifying alias.stars changed original.stars because tables are references.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Create and Modify Table
Create a table `local server = { name = "Worker-1", active = true }`.
Print `"Server " .. server.name .. " Active: " .. tostring(server.active)`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.