Dart for Luau Developers
Move from Luau to standalone Dart through typed functions, null safety, collections, errors and object contracts. Build a four-step parcel depot, use classes, interfaces and mixins, then port two complete Luau programs.
Luau and Dart side by side
The same program in Luau and in Dart, from the lessons of this course.
Output and Comments
Luau runs a script from its first line and interpolates with backtick strings and braces, as in `lane:{lane}`; its type annotations are read by the analyzer and ignored when the script runs. Dart starts at main and interpolates inside ordinary quoted strings…
Luau1local lane: number = 32print(`lane:{lane}`)Dart1void main(){final lane=3;print('lane:$lane');}Boolean Conditions
In Luau only false and nil are falsy, so 0 and the empty string count as true, and and and or return one of their operands rather than a boolean. Dart has no truthiness: conditions and the operands of && and || must be bool. Both skip an unneeded right…
Luau1local function probe(): boolean2 print("probe")3 return true4end5print(if false and probe() then "open" else "closed")Dart1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}Functions and Returns
Luau has no arrow syntax: every function is written with function ... end, and a return annotation is checked only by the analyzer, so a path that ends without return gives the caller nil. A Luau function may also return several values. A Dart arrow body is…
Luau1local function isLog(name: string): boolean2 return string.sub(name, -4) == ".log"3end4print(isLog("server.log"))Dart1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}Iterables and Laziness
Luau has no built-in map for tables, so a map helper is usually a loop that fills a new table eagerly; laziness would need an iterator function or a coroutine. Dart Iterable.map is lazy and may rerun callbacks on repeated traversal. Calling toList…
Luau1local function map(t: {number}, f: (number) -> number): {number}2 local out = {}3 for i, v in t do4 out[i] = f(v)5 end6 return out7end8 9local result = map({2, 3}, function(n)10 print(`visit:{n}`)11 return n * 212end)13print("made")14print(result[1])Dart1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}Parsing and Validation
Luau tonumber returns nil when text is not a number, but it also accepts 4.5, 1e3 and 0x10, because every Luau number is a double. Dart int.tryParse returns null on failure and rejects decimal and exponent forms. Validate strict decimal syntax and ranges…
Luau1local n = tonumber("nope")2print(if n == nil then "invalid" else n)3print(tonumber("42"))Dart1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}Classes and Instances
Luau has no class declaration: a table of methods becomes the __index of each instance's metatable, Lamp.new is an ordinary function, and a colon call passes self. Dart classes are declared in the language and keep a nominal runtime type. Separate instances…
Luau1local Lamp = {}2Lamp.__index = Lamp3 4function Lamp.new()5 return setmetatable({on = false}, Lamp)6end7 8function Lamp:toggle()9 self.on = not self.on10end11 12local a, b = Lamp.new(), Lamp.new()13a:toggle()14print(`{a.on}:{b.on}`)Dart1class Lamp{bool on=false;void toggle(){on=!on;}}2void main(){final a=Lamp(),b=Lamp();a.toggle();print('${a.on}:${b.on}');}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Dart Programs
6 lessonsFlow and Decisions
5 lessonsFunctions and Values
6 lessonsCollection Pipelines
6 lessonsParsing and Failures
3 lessonsObjects and State
6 lessonsContracts and Reuse
7 lessonsEquality and Testing
3 lessonsParcel Depot Project
4 lessonsFinal Source Ports
2 lessonsFrequently asked questions
Who is Dart for Luau Developers for?
For people who already write Luau and want to learn Dart. Each lesson starts from Luau you know and shows how Dart does the same thing, so you skip the beginner basics.
Do I need to know Dart already?
No. The course starts with your first Dart program. You need Luau basics: variables, conditions, loops, functions and collections.
How many lessons does Dart for Luau Developers have?
Dart for Luau Developers contains 48 interactive lessons you can complete at your own pace.
What does Dart for Luau Developers cover?
The course is organized into chapters covering: First Dart Programs, Flow and Decisions, Functions and Values, Collection Pipelines, and more.
Is Dart for Luau Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.