Lua for Rust Developers
Move from Rust ownership, collections and traits to Lua 5.1 tables, closures and metatable objects. Practice real multi-file modules, build a stock ledger, and port two Rust reference programs.
Rust and Lua side by side
The same program in Rust and in Lua, from the lessons of this course.
Print and Comment
Rust println! formats arguments through formatting traits and macros. Lua print converts values at runtime and separates multiple arguments with tabs. Assemble one string using .. when exact spacing is required. Rust string addition has ownership and…
Rust1fn main() {2println!("Hi, {}", "Ada");3}Lua1print("Hi" .. ", Ada")Absence and Missing Fields
Rust Option represents absence and safe references are non-null. A map can retain a key whose value is None, with lookup distinguishing absence from that stored variant. Lua nil removes the table association instead. False remains a stored value. Use a…
Rust1fn main() {2let values=std::collections::HashMap::from([("x",None::<i32>)]); println!("{}",values.contains_key("x"));3}Lua1local d = {x = nil}2print(d.x == nil)Counted Loops to Numeric for
Rust half-open ranges exclude the end while inclusive ranges use a different syntax. Lua numeric for includes its limit and takes an optional step, defaulting to one. Descending traversal requires a negative step. Translate the actual visited values and…
Rust1fn main() {2let mut total=0; for i in 1..4 {total+=i;} println!("{}",total);3}Lua1local total = 02for i = 1, 3 do total = total + i end3print(total)Functions and Returns
Rust functions declare typed parameters, with mutable references able to update caller-owned values under borrowing rules. Lua numeric parameters are local values: rebinding one does not rebind the caller’s variable. Return an updated scalar and assign it, or…
Rust1fn twice(n:i32)->i32 {n*2}Lua1local function twice(x) return x * 2 end2print(twice(4))Vectors as Dense Tables
Rust Vec.remove takes a zero-based index and shifts later values while mutable borrowing controls access. Lua table.remove similarly shifts a sequence, but uses one-based positions without borrow tracking. Assigning nil to a middle field leaves a hole…
Rust1fn main() {2let mut values=vec!["a","b","c"]; values.remove(1); println!("{}",values.join(","));3}Lua1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))Sorting and Comparators
Rust slice sorting mutates through mutable access and comparison APIs may use Ordering values or key selectors. Lua table.sort also mutates but expects a strict Boolean ordering and returns no result. Keep the sequence reference instead of assigning the sort…
Rust1fn main() {2let mut values=vec![3,1,2]; values.sort(); println!("{}",values[0]);3}Lua1local a={3,1,2}2table.sort(a)3print(a[1])
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Lua Programs
6 lessonsValues and Decisions
5 lessonsIteration and Flow
5 lessonsFunctions and Closures
5 lessonsTables as Collections
5 lessonsOrdering, Modules and Errors
5 lessonsObjects and Owned State
5 lessonsComposition and Object Lookup
6 lessonsProject: Stock Ledger
4 lessonsFinal Rust Ports
2 lessonsFrequently asked questions
Who is Lua for Rust Developers for?
For people who already write Rust and want to learn Lua. Each lesson starts from Rust you know and shows how Lua does the same thing, so you skip the beginner basics.
Do I need to know Lua already?
No. The course starts with your first Lua program. You need Rust basics: variables, conditions, loops, functions and collections.
How many lessons does Lua for Rust Developers have?
Lua for Rust Developers contains 48 interactive lessons you can complete at your own pace.
What does Lua for Rust Developers cover?
The course is organized into chapters covering: First Lua Programs, Values and Decisions, Iteration and Flow, Functions and Closures, and more.
Is Lua for Rust Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.