Menu
CoddyTech
Course

C for Luau Developers

Move from Luau to C17: explicit types, pointers, bounded arrays, strings, ownership, structs and modular interfaces. Build a multi-file stock ledger and port two Luau programs.

Luau and C side by side

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

  1. Printing and Comments

    Luau print converts each argument with tostring, separates arguments with tabs and ends the line for you, and string.format checks its arguments at run time, raising an error when %d receives a string that is not a number. C printf trusts its format string…

    Luau
    1print("value=" .. 7)
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10printf("value=%d\n",7);11return 0;12}
  2. Booleans and Branches

    In Luau only nil and false are falsy: 0 and the empty string are both truthy, so emptiness needs an explicit test such as #s == 0. C conditions test scalar values instead: zero is false and any nonzero value is true, so the 0 that Luau treats as truthy is…

    Luau
    1local s = ""2print(if s then "true" else "false")
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}
  3. Arrays Need Lengths

    A Luau table used as an array knows its length: #a counts the elements of a sequence without holes, and a function that receives the table gets a reference to that same table, so # still works there. A C array has a fixed element count, but a function array…

    Luau
    1local a = {2, 4, 6}2print(#a)
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}
  4. Function Arguments Are Values

    Luau passes every argument by value: a number, boolean or string is copied, and a table argument copies the reference, so a function can change the caller's table but never rebind the caller's variable. C parameters also receive copies of their values.…

    Luau
    1local function change(n)2    n = 93end4local x = 25change(x)6print(x)
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}
  5. Addresses and Dereferencing

    A Luau table variable holds a reference, and two variables can share one table, but Luau gives you no addresses and no pointer arithmetic. In C &object obtains an address and *pointer accesses the pointed-to object. Dereference only a valid pointer to a live…

    Luau
    1local box = {2}2local alias = box3alias[1] = 54print(box[1])
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}
  6. Parsing with Status Results

    Luau tonumber returns nil instead of raising an error when text is not a number, but it also accepts forms such as "0x1A", "1e3" and surrounding spaces. C library parsers use explicit status information. sscanf reports the number of successful assignments…

    Luau
    1local text = "12x"2print(string.match(text, "^%d+$") ~= nil)
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}

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: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, 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