Menu
CoddyTech
Course

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.

  1. 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.

    Go
    1package main2import ("fmt")3
    4func main(){5fmt.Println("Hi"+", Ada")6}
    Lua
    1-- Print one greeting.2print("Hi" .. ", Ada")
  2. 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.

    Go
    1package main2import ("fmt")3
    4func main(){5values:=map[string]*int{"x":nil}; _,ok:=values["x"]; fmt.Println(ok)6}
    Lua
    1local entry = {text = "ready"}2entry.text = nil3if entry.text == nil then4  print("absent")5else6  print("present")7end
  3. Numeric 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.

    Go
    1package main2import ("fmt")3
    4func main(){5total:=0; for i:=1;i<4;i++ {total+=i}; fmt.Println(total)6}
    Lua
    1local total = 02for i = 1, 3 do3  total = total + i4end5print(total)
  4. 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…

    Go
    1package main2import ("fmt")3func twice(n int) int {return n*2}4func main(){5fmt.Println(twice(4))6}
    Lua
    1local function twice(x)2  return x * 23end4print(twice(4))
  5. 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…

    Go
    1package main2import ("fmt"; "strings")3
    4func main(){5a:=[]string{"a","b","c"}; a=append(a[:1],a[2:]...); fmt.Println(strings.Join(a,","))6}
    Lua
    1local items = {"a", "b", "c"}2table.remove(items, 2)3print(table.concat(items, ","))
  6. 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…

    Go
    1package 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}
    Lua
    1local items = {3, 1, 2}2table.sort(items)3print(items[1])

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Go Ports

2 lessons

More courses for Go developers

Learn Lua from another language

Frequently 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.

Coddy programming languages illustration

Start Lua for Go Developers for free

Get started