Menu
CoddyTech
Course

Lua for C# Developers

Transfer C# experience to Lua 5.1: truth rules, tables, functions, module exports, errors and metatable objects. Build a stock ledger and port two C# reference programs.

C# and Lua side by side

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

  1. Print and Comment

    C# concatenates strings with + and can interpolate expressions; Lua uses .. and print separates multiple arguments with tabs. Build one string for exact spacing. C# comments use slash forms, while Lua uses double hyphens for a line comment. Lua does not parse…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5Console.WriteLine("Hi" + ", Ada");
    Lua
    1print("Hi" .. ", Ada")
  2. Null and Missing Fields

    C# reference and nullable values can be null, and a dictionary can retain a key mapped to null. Lua nil represents absence: assigning it removes a table association. False remains a stored Lua value. Test for nil when presence matters and do not translate a…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5var record=new Dictionary<string,object>{{"x",null}}; Console.WriteLine(record.ContainsKey("x"));
    Lua
    1local d = {x = nil}2print(d.x == nil)
  3. Ranges to Numeric for

    C# for states a condition and update explicitly. Lua numeric for includes its limit and advances using a supplied step, defaulting to one. Use a negative step for descending traversal and adjust an exclusive C# bound to the intended inclusive Lua endpoint.…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5int total=0; for(int i=1;i<4;i++) total+=i; Console.WriteLine(total);
    Lua
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. Functions and Returns

    C# methods and local functions have typed parameter contracts, and delegates represent callable behavior. Lua functions are values with dynamically checked operations; missing arguments become nil and extra arguments may be ignored. Define functions with…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5static int Twice(int x)=>x*2; Console.WriteLine(Twice(4));
    Lua
    1local function twice(x) return x * 2 end2print(twice(4))
  5. Lists as Dense Tables

    C# List.RemoveAt removes a zero-based position and shifts later elements. Lua table.remove similarly maintains a dense sequence with one-based positions. Assigning nil to a middle field instead creates a hole without shifting later keys. Use the dense-table…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5var values=new List<string>{"a","b","c"}; values.RemoveAt(1); Console.WriteLine(string.Join(",",values));
    Lua
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. Sorting and Comparators

    C# List.Sort mutates and its comparison returns a signed integer. Lua table.sort also mutates but its callback must return a strict Boolean ordering, such as a<b, and the sort returns no result. A numeric subtraction is truthy even when zero in Lua. Specify…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5var values=new List<int>{3,1,2}; values.Sort((a,b)=>a.CompareTo(b)); Console.WriteLine(values[0]);
    Lua
    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 Lua from another language

Frequently asked questions

Who is Lua for C# Developers for?

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

Do I need to know Lua already?

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

How many lessons does Lua for C# Developers have?

Lua for C# Developers contains 48 interactive lessons you can complete at your own pace.

What does Lua for C# Developers cover?

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

Is Lua 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 Lua for C# Developers for free

Get started