Menu
CoddyTech
Course

Luau for C Developers

Transfer C functions, structs and pointer-based APIs 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 printf interprets a format string, while Luau print converts arguments and separates them with tabs. Luau chunks execute directly without a C main function or header includes. Join text with .. or string.format when exact output matters; -- introduces a…

    C
    1#include <stdio.h>2
    3int main(void)4{5    // Print one greeting.6    printf("%s%s\n", "Hi", ", Ada");7    return 0;8}
    Luau
    1local name = "Ada"2print(`Hi, {name}`)
  2. Missing Fields and Optionals

    C often represents absence with a null pointer or a separate presence flag. Those can distinguish an existing record containing a null pointer from a missing record. Luau nil removes a table association; false remains stored. An optional annotation describes…

    C
    1#include <stdio.h>2
    3struct Entry {4    int present;5    const char *text;6};7
    8int main(void)9{10    struct Entry entry = {1, NULL};11    puts(entry.present ? "present" : "absent");12    return 0;13}
    Luau
    1local d = {x = nil}2print(d.x == nil)
  3. Inclusive Numeric Loops

    C for loops have separate initialization, condition and update expressions. Luau numeric for uses an inclusive final bound and an optional step. Adjust an exclusive C stop accordingly, and give a negative step for descending traversal. Count actual visited…

    C
    1#include <stdio.h>2
    3int main(void)4{5    int total = 0;6    for (int i = 1; i < 3; ++i) {7        total += i;8    }9    printf("%d\n", total);10    return 0;11}
    Luau
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. Functions and Returns

    C prototypes constrain parameter and return types, and pointer parameters can expose caller storage for mutation. Luau typed signatures describe static expectations, but this runner does not invoke the analyzer. Numeric rebinding stays local; table fields can…

    C
    1#include <stdio.h>2static int twice(int x) {3    return x * 2;4}5int main(void) {6    printf("%d\n", twice(4));7    return 0;8}
    Luau
    1local function twice(x: number): number return x * 2 end2print(twice(4))
  5. Lists as Dense Tables

    C array capacity and logical length are separate concerns, and deletion often requires shifting elements. Luau table.remove shifts a dense sequence, while assigning nil creates a hole. The length operator is not a substitute for counting arbitrary dictionary…

    C
    1#include <stddef.h>2#include <stdio.h>3int main(void) {4    const char *items[] = {"a", "b", "c"};5    size_t length = sizeof items / sizeof items[0];6    for (size_t i = 1; i + 1 < length; ++i) {7        items[i] = items[i + 1];8    }9    --length;10    for (size_t i = 0; i < length; ++i) {11        printf("%s%s", i == 0 ? "" : ",", items[i]);12    }13    putchar('\n');14    return 0;15}
    Luau
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. Sorting and Comparators

    C qsort expects a negative, zero or positive comparator result. Luau table.sort expects a Boolean strict ordering predicate and mutates the sequence in place. Returning a numeric difference is wrong because zero is truthy. Use a real comparison and retain the…

    C
    1#include <stdio.h>2#include <stdlib.h>3static int compare(const void *left, const void *right) {4    int a = *(const int *)left;5    int b = *(const int *)right;6    return (a > b) - (a < b);7}8int main(void) {9    int items[] = {3, 1, 2};10    qsort(items, sizeof items / sizeof items[0], sizeof items[0], compare);11    printf("%d\n", items[0]);12    return 0;13}
    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