Menu
CoddyTech
Course

Kotlin for Lua Developers

Move from Lua to Kotlin through null safety, collection ownership, functions, properties and object contracts. Compare tables, closures and method calls, build an order processor, and port a stock ledger.

Lua and Kotlin side by side

The same program in Lua and in Kotlin, from the lessons of this course.

  1. Strings and Templates

    Lua concatenates strings with double dots and formats text with string.format. Kotlin interpolates names and expressions inside strings, and println adds a newline. Lua print separates multiple arguments with tabs, so assemble exact output deliberately. Lua…

    Lua
    1local name="Ada"; print("Hi "..name.."!")
    Kotlin
    1fun main(){2val ready=33println("Ready: $ready")4}
  2. Equality and Identity

    Lua strings compare their byte contents, while table equality normally compares identity unless a metamethod applies. Kotlin == invokes null-safe equals and === tests identity. Strings have content equality, but ordinary classes do not automatically compare…

    Lua
    1local a="ab"; local b="a".."b"; print(a==b)
    Kotlin
    1fun main(){2val a=String(charArrayOf('t','e','a'))3val b=String(charArrayOf('t','e','a'))4println(a==b)5}
  3. Arrays and IntArray

    Lua sequences are tables rather than fixed-size typed arrays, and # does not count arbitrary sparse keys reliably. Kotlin arrays have fixed size, checked zero-based indexes and declared element types. IntArray provides primitive integer storage on the JVM.…

    Lua
    1local values={2,4,6}; print(values[#values])
    Kotlin
    1fun main(){2val a=intArrayOf(4,8,12)3println(a.last())4}
  4. While, Break, and Continue

    Lua 5.4 supports while and break but has no continue keyword. Kotlin continue skips the remainder of one iteration, while break ends traversal. When translating a guarded source loop, ensure a manual index advances on every continuing path. Kotlin requires…

    Lua
    1local n=3; while n>1 do n=n-1 end; print(n)
    Kotlin
    1fun main(){2val kept=mutableListOf<String>()3for(word in listOf("tea","","STOP","coffee")){if(word=="STOP")break;if(word.isEmpty())continue;kept.add(word)}4println(kept.joinToString(","))5}
  5. Top-level Functions

    Lua functions are first-class values and can return multiple results whose adjustment depends on context. Kotlin top-level functions declare parameter and result types and return one value, which can be a result model or pair. Kotlin parameters are read-only…

    Lua
    1local function hours(total) return total//60 end; print(hours(125))
    Kotlin
    1fun isLong(text:String):Boolean = text.length>42fun main(){3println(isLong("coffee"))4}
  6. Input and String Formatting

    Lua io.read can read lines or numbers, while the Kotlin task driver supplies the input lines to the editable API. Kotlin readlnOrNull represents EOF as null, and toInt requires a complete valid integer string. Trim only when permitted and format exact…

    Lua
    1local cents=305; print(string.format("tea: %d.%02d",cents//100,cents%100))
    Kotlin
    1fun main(){2println("  tea  ".trim().uppercase(java.util.Locale.ROOT))3}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Challenges

2 lessons

More courses for Lua developers

Learn Kotlin from another language

Frequently asked questions

Who is Kotlin for Lua Developers for?

For people who already write Lua and want to learn Kotlin. Each lesson starts from Lua you know and shows how Kotlin does the same thing, so you skip the beginner basics.

Do I need to know Kotlin already?

No. The course starts with your first Kotlin program. You need Lua basics: variables, conditions, loops, functions and collections.

How many lessons does Kotlin for Lua Developers have?

Kotlin for Lua Developers contains 48 interactive lessons you can complete at your own pace.

What does Kotlin for Lua Developers cover?

The course is organized into chapters covering: Starting Kotlin, Values and Decisions, Collections and Ownership, Iteration and Transformations, and more.

Is Kotlin 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.

Coddy programming languages illustration

Start Kotlin for Lua Developers for free

Get started