Menu
CoddyTech
Course

Luau for C++ Developers

Transfer C++ ownership, containers and classes to Luau tables, closures and typed signatures. Practice runtime validation, relative modules and metatable objects, build a stock ledger and port two C++ programs.

C++ and Luau side by side

The same program in C++ and in Luau, from the lessons of this course.

  1. Print and Comment

    C++ streams format values through insertion operators; Luau print converts arguments and separates them with tabs. Luau chunks need no main function or header includes. Concatenate with .. when exact spacing matters, and return task results to the driver…

    C++
    1#include <iostream>2#include <string>3int main() {4std::cout << std::string("Hi") + ", Ada" << "\n";5}
    Luau
    1local name = "Ada"2print(`Hi, {name}`)
  2. Missing Fields and Optionals

    C++ optional values, null pointers and missing map keys represent different forms of absence. A map may retain an entry containing an empty optional. Luau nil removes an association, while false remains stored. Use a state record or sentinel if the port must…

    C++
    1#include <iostream>2#include <string>3#include <map>4#include <optional>5int main() {6std::map<std::string, std::optional<int>> d;7d["x"] = std::nullopt;8std::cout << std::boolalpha << (d.count("x") != 0) << "\n";9}
    Luau
    1local d = {x = nil}2print(d.x == nil)
  3. Inclusive Numeric Loops

    C++ counted loops can stop before an exclusive bound. Luau numeric for includes its final bound and takes an explicit step when needed. Translate the actual sequence of values, including descending and empty cases, instead of copying the old limit unchanged.

    C++
    1#include <iostream>2int main() {3int total = 0;4for (int i = 1; i <= 3; ++i) total += i;5std::cout << total << "\n";6}
    Luau
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. Functions and Returns

    C++ references can update caller-owned scalars, while value parameters cannot rebind the caller’s variable. Luau numeric parameters are local values; return and assign a replacement. Tables permit shared field mutation. Luau annotations describe static…

    C++
    1#include <iostream>2int twice(int x) {3    x *= 2;4    return x;5}6int main() {7int value = 4;8std::cout << twice(value) << ':' << value << '\n';9}
    Luau
    1local function twice(x: number): number return x * 2 end2print(twice(4))
  5. Lists as Dense Tables

    C++ vector manages a contiguous sequence and shifts later elements when erasing an element. Luau dense tables use one-based keys and table.remove performs that shift. Setting a slot to nil creates a hole instead. Do not apply sequence length rules to…

    C++
    1#include <iostream>2#include <string>3#include <vector>4int main() {5std::vector<std::string> values{"a", "b", "c"};6values.erase(values.begin() + 1);7std::cout << values[0] << ',' << values[1] << '\n';8}
    Luau
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. Sorting and Comparators

    C++ std::sort and Luau table.sort both use a Boolean strict ordering predicate and mutate the sequence. Luau table.sort returns no sequence result. Retain the original table reference and define a tie-breaker when equal primary keys need deterministic output.

    C++
    1#include <iostream>2#include <vector>3#include <algorithm>4int main() {5std::vector<int> values{3, 1, 2};6std::sort(values.begin(), values.end());7std::cout << values[0] << '\n';8}
    Luau
    1local a={3,1,2}2table.sort(a)3print(a[1])

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Source Ports

2 lessons

More courses for C++ developers

Learn Luau from another language

Frequently asked questions

Who is Luau for C++ Developers for?

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

Do I need to know Luau already?

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

How many lessons does Luau for C++ Developers have?

Luau for C++ Developers contains 48 interactive lessons you can complete at your own pace.

What does Luau for C++ Developers cover?

The course is organized into chapters covering: First Luau Programs, Values and Decisions, Iteration and Flow, Functions and Closures, and more.

Is Luau for C++ 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 Luau for C++ Developers for free

Get started