Menu
CoddyTech
Course

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.

  1. 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…

    Luau
    1local lane: number = 32print(`lane:{lane}`)
    Dart
    1void main(){final lane=3;print('lane:$lane');}
  2. 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…

    Luau
    1local function probe(): boolean2	print("probe")3	return true4end5print(if false and probe() then "open" else "closed")
    Dart
    1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}
  3. 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…

    Luau
    1local function isLog(name: string): boolean2	return string.sub(name, -4) == ".log"3end4print(isLog("server.log"))
    Dart
    1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}
  4. 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…

    Luau
    1local 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])
    Dart
    1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}
  5. 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…

    Luau
    1local n = tonumber("nope")2print(if n == nil then "invalid" else n)3print(tonumber("42"))
    Dart
    1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}
  6. 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…

    Luau
    1local 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}`)
    Dart
    1class 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 questions

More courses for Luau developers

Learn Dart from another language

Frequently 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.

Coddy programming languages illustration

Start Dart for Luau Developers for free

Get started