Lua for Swift Developers
Transfer Swift experience to Lua 5.1: truth rules, tables, functions, module exports, errors and metatable objects. Build a stock ledger and port two Swift reference programs.
Swift and Lua side by side
The same program in Swift and in Lua, from the lessons of this course.
Print and Comment
Swift print accepts a separator and terminator and interpolation converts values into text. Lua print inserts tabs between arguments and a final newline. Build one string with .. when exact formatting matters, and return it to the locked driver. Lua comments…
Swift1let name = "Ada"2print("Hi, \(name)")Lua1print("Hi" .. ", Ada")Nil and Missing Fields
Swift Optional represents a missing value with nil and distinguishes it from false. Dictionary lookup adds an optional layer, and assigning nil through a dictionary subscript removes its entry. Lua nil likewise removes a table association, but Lua has no…
Swift1var values = ["x": 1]2values["x"] = nil3print(values.count)Lua1local d = {x = nil}2print(d.x == nil)Ranges to Numeric for
Swift half-open ranges exclude their upper bound and closed ranges include it. Lua numeric for always includes its limit and accepts an optional step. Translate the values actually visited, and use a negative step for descending traversal. Keep empty-range…
Swift1var total = 02for i in 1..<4 { total += i }3print(total)Lua1local total = 02for i = 1, 3 do total = total + i end3print(total)Functions and Returns
Swift function signatures declare parameter and return types; inout explicitly permits writeback to caller storage. Lua parameters have no declared types. Rebinding a numeric parameter affects only its local name, so return and assign an updated scalar.…
Swift1func twice(_ n: Int) -> Int { n * 2 }2print(twice(4))Lua1local function twice(x) return x * 2 end2print(twice(4))Lists as Dense Tables
Swift Array is a value type with zero-based indexing and copy-on-write storage. Lua represents dense lists with one-based table keys. table.insert and table.remove shift sequence elements; assigning nil leaves a hole instead. The length operator is reliable…
Swift1var values = [2, 3]2values.append(4)3print(values.count)Lua1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))Sorting and Comparators
Swift sort mutates a collection and sorted returns a new collection; both accept a Boolean ordering predicate. Lua table.sort mutates the sequence and returns no value. Its comparator must report strict ordering. Keep the original table reference, and add a…
Swift1var values = [10, 2, 1]2values.sort(by: <)3print(values.map(String.init).joined(separator: ","))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 Source Ports
2 lessonsFrequently asked questions
Who is Lua for Swift Developers for?
For people who already write Swift and want to learn Lua. Each lesson starts from Swift 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 Swift basics: variables, conditions, loops, functions and collections.
How many lessons does Lua for Swift Developers have?
Lua for Swift Developers contains 48 interactive lessons you can complete at your own pace.
What does Lua for Swift 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 Swift Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.