Lua for Kotlin Developers
Transfer Kotlin experience to Lua 5.1: truth rules, tables, functions, module exports, errors and metatable objects. Build a stock ledger and port two Kotlin reference programs.
Kotlin and Lua side by side
The same program in Kotlin and in Lua, from the lessons of this course.
Print and Comment
Kotlin uses string templates or + to construct strings and println emits one completed value. Lua concatenates with .. and print separates multiple arguments with tabs. Build exact spacing explicitly. Kotlin slash-style comments become double-hyphen Lua…
Kotlin1 2fun main(){3println("Hi"+", Ada")4}Lua1print("Hi" .. ", Ada")Null and Missing Fields
Kotlin nullable types allow null values, and a map can retain a key mapped to null. Lua nil represents absence and removes a field when assigned. False remains stored. Test for nil when checking presence and choose a separate sentinel if the domain needs a…
Kotlin1 2fun main(){3val record=mapOf<String,Int?>("x" to null)4println(record.containsKey("x"))5}Lua1local d = {x = nil}2print(d.x == nil)Ranges to Numeric for
Kotlin until excludes its upper bound and double-dot ranges include it. Lua numeric for includes its limit and uses an optional step, defaulting to one. Use a negative step for descending loops. Translate the visited values rather than copy range punctuation…
Kotlin1 2fun main(){3var total=04for(i in 1 until 4) total+=i5println(total)6}Lua1local total = 02for i = 1, 3 do total = total + i end3print(total)Functions and Returns
Kotlin supports top-level and local functions with typed parameters and results. Lua functions are direct dynamically typed values: missing arguments become nil and extra arguments can be ignored. Use function/end and document the expected boundary. Validate…
Kotlin1fun twice(n:Int)=n*22fun main(){3println(twice(4))4}Lua1local function twice(x) return x * 2 end2print(twice(4))Lists as Dense Tables
Kotlin MutableList.removeAt takes a zero-based position and shifts later elements; remove chooses a value. Lua table.remove similarly shifts a dense sequence but uses one-based positions. Assigning nil to a middle field creates a hole instead. Keep the…
Kotlin1 2fun main(){3val values=mutableListOf("a","b","c")4values.removeAt(1)5println(values.joinToString(","))6}Lua1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))Sorting and Comparators
Kotlin Comparator returns a signed integer, while sortedBy selects keys and returns a new result. Lua table.sort mutates its sequence and expects a strict Boolean ordering, such as a<b. A numeric difference is unsuitable because every number is truthy. Decide…
Kotlin1 2fun main(){3val values=mutableListOf(3,1,2)4values.sortWith(compareBy {it})5println(values[0])6}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 Kotlin Developers for?
For people who already write Kotlin and want to learn Lua. Each lesson starts from Kotlin 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 Kotlin basics: variables, conditions, loops, functions and collections.
How many lessons does Lua for Kotlin Developers have?
Lua for Kotlin Developers contains 48 interactive lessons you can complete at your own pace.
What does Lua for Kotlin 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 Kotlin Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.