Dart for Lua Developers
Move from Lua 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 Lua programs.
Lua and Dart side by side
The same program in Lua and in Dart, from the lessons of this course.
Output and Comments
Lua builds text with the .. operator or string.format, and its comments start with --. Dart interpolation uses dollar-prefixed names or braces in ordinary strings, comments use //, and execution begins in main rather than at the top of the chunk.
Lua1local lane = 32print('lane:' .. lane)Dart1void main(){final lane=3;print('lane:$lane');}Boolean Conditions
In Lua only nil and false are falsy, so 0 and the empty string count as true, and and/or return one of their operands rather than a Boolean. Dart conditions and logical operands require bool. Both short-circuit, so a skipped right operand has no side effects.
Lua1local function probe()2 print('probe')3 return true4end5if false and probe() then6 print('open')7else8 print('closed')9endDart1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}Functions and Returns
A Lua function that ends without return gives its caller no values, which reads as nil, and a Lua function can return several values at once. Dart non-nullable result types require compatible returns on all normal paths, and each call returns one value. Arrow…
Lua1local function isLog(name)2 return name:sub(-4) == '.log'3end4print(isLog('server.log'))Dart1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}Iterables and Laziness
Lua has no built-in map: a loop that fills a new table calls the function on every element at once. Laziness in Lua comes from an iterator function or a coroutine, which produces values on request and is used up after one pass. Dart map returns a lazy…
Lua1local function double(n)2 print('visit:' .. n)3 return n * 24end5local result = coroutine.wrap(function()6 for _, n in ipairs({2, 3}) do7 coroutine.yield(double(n))8 end9end)10print('made')11print(result())Dart1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}Parsing and Validation
Lua tonumber returns nil on invalid text instead of raising an error, and it accepts forms a strict integer format may reject, such as 4.2e1 (a float) or 0x1F. Dart tryParse returns null, while parse throws. Keep syntax and range validation separate.
Lua1print(tonumber('nope') or 'invalid')2print(tonumber('42'))Dart1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}Classes and Instances
Lua has no class keyword: a class is a table of methods shared through a metatable's __index, the colon syntax passes self implicitly, and fields can be added to any instance at runtime. Dart fields and method types are declared by the class; this is implicit…
Lua1local Lamp = {}2Lamp.__index = Lamp3function Lamp.new() return setmetatable({on = false}, Lamp) end4function Lamp:toggle() self.on = not self.on end5local a, b = Lamp.new(), Lamp.new()6a:toggle()7print(tostring(a.on) .. ':' .. tostring(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 Lua Developers for?
For people who already write Lua and want to learn Dart. Each lesson starts from Lua 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 Lua basics: variables, conditions, loops, functions and collections.
How many lessons does Dart for Lua Developers have?
Dart for Lua Developers contains 48 interactive lessons you can complete at your own pace.
What does Dart for Lua 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 Lua Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.