Lua for Dart Developers
Transfer Dart experience to Lua 5.1: truth rules, tables, functions, module exports, errors and metatable objects. Build a stock ledger and port two Dart reference programs.
Dart and Lua side by side
The same program in Dart and in Lua, from the lessons of this course.
Print and Comment
Dart supports string interpolation and concatenation with +. Lua concatenates with .. and print separates multiple arguments using tabs. Build one string to control exact spacing. Dart uses slash-style comments while Lua line comments begin with double…
Dart1 2void main() {3print("Hi" + ", Ada");4}Lua1print("Hi" .. ", Ada")Null and Missing Fields
Dart null safety distinguishes nullable types and a map can retain a key whose value is null. Lua nil means absence; assigning nil removes the table entry. False is a valid stored value in Lua. Use an explicit nil check when deciding whether a field exists…
Dart1 2void main() {3final record=<String,int?>{"x":null}; print(record.containsKey("x"));4}Lua1local d = {x = nil}2print(d.x == nil)Ranges to Numeric for
Dart counted for loops state a condition and update explicitly. Lua numeric for includes the limit, with a default step of one and an explicit negative step for descending loops. Convert an exclusive Dart bound into the intended inclusive endpoint. Lua has no…
Dart1 2void main() {3var total=0; for(var i=1;i<4;i++){total+=i;} print(total);4}Lua1local total = 02for i = 1, 3 do total = total + i end3print(total)Functions and Returns
Dart top-level functions and closures have statically checked function types. Lua functions are dynamically typed values: missing arguments become nil and extra arguments may be ignored. Use function/end rather than an arrow declaration, document the required…
Dart1 2void main() {3int twice(int x)=>x*2; print(twice(4));4}Lua1local function twice(x) return x * 2 end2print(twice(4))Lists as Dense Tables
Dart growable lists remove a zero-based position with removeAt and shift following elements. Lua table.remove does the equivalent using one-based positions. Assigning nil to a middle entry leaves a hole without shifting. Keep sequences dense when using…
Dart1 2void main() {3final values=["a","b","c"]; values.removeAt(1); print(values.join(","));4}Lua1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))Sorting and Comparators
Dart List.sort mutates the list and its comparator returns a signed integer. Lua table.sort also mutates but expects a strict Boolean comparison such as a<b and returns no result. Numeric comparator results are unsuitable because every number, including zero…
Dart1 2void main() {3final values=[3,1,2]; values.sort((a,b)=>a.compareTo(b)); print(values[0]);4}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 Dart Developers for?
For people who already write Dart and want to learn Lua. Each lesson starts from Dart 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 Dart basics: variables, conditions, loops, functions and collections.
How many lessons does Lua for Dart Developers have?
Lua for Dart Developers contains 48 interactive lessons you can complete at your own pace.
What does Lua for Dart 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 Dart Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.