Menu
CoddyTech
Course

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.

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

    Kotlin
    1
    2fun main(){3println("Hi"+", Ada")4}
    Lua
    1print("Hi" .. ", Ada")
  2. 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…

    Kotlin
    1
    2fun main(){3val record=mapOf<String,Int?>("x" to null)4println(record.containsKey("x"))5}
    Lua
    1local d = {x = nil}2print(d.x == nil)
  3. 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…

    Kotlin
    1
    2fun main(){3var total=04for(i in 1 until 4) total+=i5println(total)6}
    Lua
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. 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…

    Kotlin
    1fun twice(n:Int)=n*22fun main(){3println(twice(4))4}
    Lua
    1local function twice(x) return x * 2 end2print(twice(4))
  5. 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…

    Kotlin
    1
    2fun main(){3val values=mutableListOf("a","b","c")4values.removeAt(1)5println(values.joinToString(","))6}
    Lua
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. 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…

    Kotlin
    1
    2fun main(){3val values=mutableListOf(3,1,2)4values.sortWith(compareBy {it})5println(values[0])6}
    Lua
    1local a={3,1,2}2table.sort(a)3print(a[1])

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Kotlin developers

Learn Lua from another language

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

Coddy programming languages illustration

Start Lua for Kotlin Developers for free

Get started