GDScript for Lua Developers
Move from Lua 5.1 tables, closures and metatables to Godot 4 GDScript: typed arrays, script classes, signals and failure contracts. Build a stock depot through 48 multi-file console lessons.
Lua and GDScript side by side
The same program in Lua and in GDScript, from the lessons of this course.
Text and Comments
A Lua chunk runs its top-level statements when loaded. GDScript statements execute inside methods; the supplied Node enters _ready(). Lua starts line comments with --, while GDScript uses #. Both print functions add a newline, but Lua separates arguments with…
Lua1io.write("tag ", 7, "\n")2print("# data")GDScript1extends Node2 3func _ready() -> void:4 print("tag", 7)5 print("# data")Branches and Values
Lua closes branches with end and spells the middle branch elseif. GDScript uses indentation, colons and elif. Both test branches in order and choose the first matching one. Lua has no built-in conditional expression; the common condition and value or fallback…
Lua1local n = -22local label3if n < 0 then label = "west" else label = "east" end4print(label)GDScript1extends Node2 3func _ready() -> void:4 var n: int = -25 print("west" if n < 0 else "east")Array Operations
A Lua sequence is a convention over a table with consecutive positive integer keys starting at one. A GDScript Array is a dedicated ordered container indexed from zero; valid negative indices count from the end. Lua # is not a reliable count of all entries in…
Lua1local items = {3}2table.insert(items, 8)3local removed = table.remove(items)4print(string.format("%d %d", removed, #items))GDScript1extends Node2 3func _ready() -> void:4 var items: Array = [3]5 items.append(8)6 var removed = items.pop_back()7 print("%d %d" % [removed,items.size()])String Operations
Lua concatenates strings with ..; GDScript uses +. Lua strings are immutable byte sequences, while GDScript String uses Unicode text with value semantics. Replacement returns new text in both examples. Lua string.gsub uses Lua patterns rather than regular…
Lua1local s = "a-b-a"2local t, count = string.gsub(s, "%-", "/")3print(s .. " " .. t)4print(count)GDScript1extends Node2 3func _ready() -> void:4 var s: String = "a-b-a"5 var t: String = s.replace("-","/")6 print(s," ",t)Scripts as Classes
Lua has no built-in class declaration. A common prototype pattern sets a table's __index to a method table, with setmetatable connecting each instance to it. Constructor functions decide which fields belong to each instance. GDScript instead treats each…
Lua1local Token = {}2Token.__index = Token3function Token.new()4 return setmetatable({text = "blue"}, Token)5end6return TokenGDScript1class_name DemoToken2extends RefCounted3var text: String = "blue"Inheritance and Super
Lua can chain prototype tables through metatables, but there is no language-level base class or built-in super call. An override can call a known base function and pass self explicitly. GDScript supports a single direct base with extends; overrides can call…
Lua1local Base = {}2function Base:label() return "base" end3return BaseGDScript1class_name DemoBase2extends RefCounted3func label() -> String:4 return "base"
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsScripts and Scalar Values
6 lessonsFlow and Functions
6 lessonsCollection Ownership
6 lessonsText and Callable Values
3 lessonsObjects and State
5 lessonsObject Relationships
5 lessonsEvents and Failure
5 lessonsBoundaries and Lifetimes
6 lessonsConnected Stock Depot
Project4 lessonsFinal Ports
2 lessonsFrequently asked questions
Who is GDScript for Lua Developers for?
For people who already write Lua and want to learn GDScript. Each lesson starts from Lua you know and shows how GDScript does the same thing, so you skip the beginner basics.
Do I need to know GDScript already?
No. The course starts with your first GDScript program. You need Lua basics: variables, conditions, loops, functions and collections.
How many lessons does GDScript for Lua Developers have?
GDScript for Lua Developers contains 48 interactive lessons you can complete at your own pace.
What does GDScript for Lua Developers cover?
The course is organized into chapters covering: Scripts and Scalar Values, Flow and Functions, Collection Ownership, Text and Callable Values, and more.
Is GDScript for Lua Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.