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.
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…
Luau1print(#"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}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…
Luau1local 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}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…
Luau1local 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}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…
Luau1local 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}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…
Luau1local 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}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…
Luau1local 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 questionsC++ Files and Values
6 lessonsConditions and Iteration
5 lessonsStandard Containers
5 lessonsCopies and Algorithms
5 lessonsFunctions and Templates
5 lessonsParsing and Lifetime
5 lessonsObjects and Invariants
6 lessonsComposition and Ownership
5 lessonsProject: Library Desk
4 lessonsFinal Challenges
2 lessonsFrequently 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.