Menu
CoddyTech
Course

C++ for Luau Developers

Transfer Luau experience to C++17: values, flow, functions, containers, headers, classes, virtual dispatch, RAII, and move ownership. Build a connected library desk.

Luau and C++ side by side

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

  1. Strings and Output

    Luau strings are immutable byte sequences: every edit, such as .. or string.upper, builds a new string. C++ std::string owns a mutable byte sequence that can change in place; stream insertion formats values. In both languages length counts bytes, not Unicode…

    Luau
    1print(#"oak")
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::string name="oak";std::cout<<name.size()<<"\n";15}
  2. Text Equality

    Luau == compares strings by content but tables by identity: two separate tables holding the same values are unequal unless an __eq metamethod says otherwise. C++ operator behavior depends on the declared operand types. C++ std::string equality compares…

    Luau
    1local a = {"red"}2local b = {"red"}3print(a == b)4print(a[1] == b[1])
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::string a="red",b="red";std::cout<<std::boolalpha<<(a==b)<<"\n";15}
  3. Fixed-size Arrays

    A Luau table used as an array grows on demand, starts at index 1, and is shared by reference: assigning it to another local creates an alias, not a copy. C++ std::array<T,N> is a fixed-size value type indexed from 0. Its size is part of its type, and normal…

    Luau
    1local items = {4, 8}2local alias = items3table.insert(alias, 12)4print(#items)5print(items[3])
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::array<int,3> a{4,5,6};std::cout<<a.size()<<" "<<a.at(1)<<"\n";15}
  4. Value Copies

    Luau assignment shares a table, and table.clone copies only the top level, so nested tables stay shared. C++ vector copy copies its elements according to their types. C++ vector and string copies own independent storage. Copying a raw pointer still shares the…

    Luau
    1local original = {{1}}2local copy = table.clone(original)3table.insert(copy[1], 2)4print(#original[1])5print(original[1] == copy[1])
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::vector<int> a{4};auto b=a;b.push_back(9);std::cout<<a.size()<<" "<<b.size()<<"\n";15}
  5. Functions and Returns

    Luau functions are first-class values, and type annotations are checked by the type checker but not enforced when the code runs. C++ function signatures are statically checked. C++ function declarations establish parameter and return types. A return value is…

    Luau
    1local function twice(value: number): number2    return value * 23end4print(twice(4))
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12int triple(int n){return 3*n;}13int main(){14std::cout<<triple(4)<<"\n";15}
  6. Streams and Exact Parsing

    Luau tonumber returns nil for text that is not a number, and string.match returns nil when its pattern does not match; neither raises an error. C++ streams represent extraction failure in stream state. C++ stream extraction reports success through stream…

    Luau
    1local word, number = string.match("oak 7", "^(%a+) (%d+)$")2print(`{word}/{tonumber(number)}/{tonumber("7x")}`)
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::istringstream in("oak 7");std::string word;int n;if(in>>word>>n)std::cout<<word<<"/"<<n<<"\n";15}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Luau developers

Learn C++ from another language

Frequently asked questions

Who is C++ for Luau Developers for?

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

Do I need to know C++ already?

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

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

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

What does C++ for Luau Developers cover?

The course is organized into chapters covering: C++ Files and Values, Conditions and Iteration, Standard Containers, Copies and Algorithms, and more.

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

Get started