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.
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");Lua1print("Hi" .. ", Ada")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"));Lua1local d = {x = nil}2print(d.x == nil)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);Lua1local total = 02for i = 1, 3 do total = total + i end3print(total)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));Lua1local function twice(x) return x * 2 end2print(twice(4))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));Lua1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))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]);Lua1local a={3,1,2}2table.sort(a)3print(a[1])
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Lua Programs
6 lessonsValues and Decisions
5 lessonsIteration and Flow
5 lessonsFunctions and Closures
5 lessonsTables as Collections
5 lessonsOrdering, Modules and Errors
5 lessonsObjects and Owned State
5 lessonsComposition and Object Lookup
6 lessonsProject: Stock Ledger
4 lessonsFinal Source Ports
2 lessonsFrequently 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.