Lua for Go Developers
Move from Go to Lua 5.1 through numbers, truth rules, tables, closures, modules and metatable objects. Build a stock ledger and port complete Go inventory and room-reservation programs.
Go and Lua side by side
The same program in Go and in Lua, from the lessons of this course.
Print and Comment
Go fmt.Println formats values and separates its arguments with spaces. Lua print uses tabs between multiple arguments, so build a single string when exact spacing matters. Lua concatenates with double dots rather than Go’s string plus operator.
Go1package main2import ("fmt")3 4func main(){5fmt.Println("Hi"+", Ada")6}Lua1-- Print one greeting.2print("Hi" .. ", Ada")Absence and Table Fields
Go map lookup can return a value and an ok flag, separating an absent key from a stored zero or nil. Lua table lookup returns nil for absence, and assigning nil removes the association. False remains a valid stored Lua value.
Go1package main2import ("fmt")3 4func main(){5values:=map[string]*int{"x":nil}; _,ok:=values["x"]; fmt.Println(ok)6}Lua1local entry = {text = "ready"}2entry.text = nil3if entry.text == nil then4 print("absent")5else6 print("present")7endNumeric for and Limits
Go counted for loops specify initialization, a condition and an update. Lua numeric for includes its limit and uses an optional step, which defaults to one. A negative step is required for descending traversal.
Go1package main2import ("fmt")3 4func main(){5total:=0; for i:=1;i<4;i++ {total+=i}; fmt.Println(total)6}Lua1local total = 02for i = 1, 3 do3 total = total + i4end5print(total)Functions and Arguments
Go functions have static parameter and result types and can be passed as values. Lua functions are values too, but missing arguments become nil and extra arguments can be ignored. Define the contract with function/end and validate input before operations that…
Go1package main2import ("fmt")3func twice(n int) int {return n*2}4func main(){5fmt.Println(twice(4))6}Lua1local function twice(x)2 return x * 23end4print(twice(4))Arrays to Dense Tables
Go slices describe shared backing arrays and removing an element requires an explicit slice operation or loop. Lua table.remove shifts later elements in a dense one-based sequence. Setting a middle field to nil instead leaves a hole. Keep sequence invariants…
Go1package main2import ("fmt"; "strings")3 4func main(){5a:=[]string{"a","b","c"}; a=append(a[:1],a[2:]...); fmt.Println(strings.Join(a,","))6}Lua1local items = {"a", "b", "c"}2table.remove(items, 2)3print(table.concat(items, ","))Sorting and Comparators
Go sort.Slice uses a Boolean less function and mutates the slice; Lua table.sort also uses a strict Boolean ordering and mutates the sequence. Neither requires a signed subtraction result. Preserve strictness for equal values and specify tie-breaking…
Go1package main2import ("fmt"; "sort")3 4func main(){5a:=[]int{3,1,2}; sort.Slice(a,func(i,j int)bool{return a[i]<a[j]}); fmt.Println(a[0])6}Lua1local items = {3, 1, 2}2table.sort(items)3print(items[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 Go Ports
2 lessonsFrequently asked questions
Who is Lua for Go Developers for?
For people who already write Go and want to learn Lua. Each lesson starts from Go 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 Go basics: variables, conditions, loops, functions and collections.
How many lessons does Lua for Go Developers have?
Lua for Go Developers contains 48 interactive lessons you can complete at your own pace.
What does Lua for Go 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 Go Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.