Lua for TypeScript Developers
Transfer TypeScript experience to Lua 5.1: truth rules, tables, functions, module exports, errors and metatable objects. Build a stock ledger and port two source-language reference programs.
TypeScript and Lua side by side
The same program in TypeScript and in Lua, from the lessons of this course.
Print and Comment
JavaScript concatenates strings with +; Lua uses .. and print separates multiple arguments with tabs. Build one string for exact spacing. The string annotation disappears at runtime. Lua has no TypeScript annotation syntax.
TypeScript1const greeting: string = "Hi" + ", Ada";2console.log(greeting);Lua1print("Hi" .. ", Ada")Undefined and Missing Fields
An object can retain a JavaScript property whose value is undefined. A Lua table field assigned nil is removed. False remains a stored Lua value. An optional property type describes possible absence; it does not delete an explicitly assigned undefined…
TypeScript1const record: {x?: number} = {x: undefined};2console.log("x" in record);Lua1local d = {x = nil}2print(d.x == nil)Ranges to Numeric for
JavaScript for has an explicit condition and update. Lua numeric for includes its limit, so the corresponding range is for i=1,3 do. A negative step is needed for descending Lua loops. Annotating a loop variable does not change JavaScript bounds. Lua for-loop…
TypeScript1let total: number = 0;2for (let i: number = 1; i < 4; i++) total += i;3console.log(total);Lua1local total = 02for i = 1, 3 do total = total + i end3print(total)Functions and Returns
JavaScript and Lua functions are values. Missing JavaScript arguments become undefined; missing Lua arguments become nil. Lua uses function/end and no arrow syntax. TypeScript can reject a missing required argument statically. Lua does not enforce that…
TypeScript1function twice(x: number): number { return x * 2; }2console.log(twice(4));Lua1local function twice(x) return x * 2 end2print(twice(4))Lists as Dense Tables
JavaScript splice removes and shifts elements. Lua table.remove does the same with one-based indexes. JavaScript delete and Lua assignment to nil both risk holes instead of a dense sequence. A TypeScript array annotation does not change splice indexes or turn…
TypeScript1const a: string[]=["a","b","c"];2a.splice(1,1);3console.log(a.join(","));Lua1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))Sorting and Comparators
JavaScript sort mutates and returns the array; its comparator returns a signed number. Lua table.sort mutates but returns no result, and its comparator returns a strict boolean ordering. TypeScript types can distinguish a numeric comparator from a boolean…
TypeScript1const a: number[]=[3,1,2];2a.sort((x: number,y: number): number=>x-y);3console.log(a[0]);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 TypeScript Developers for?
For people who already write TypeScript and want to learn Lua. Each lesson starts from TypeScript 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 TypeScript basics: variables, conditions, loops, functions and collections.
How many lessons does Lua for TypeScript Developers have?
Lua for TypeScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Lua for TypeScript 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 TypeScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.