Lua for Ruby Developers
Transfer Ruby skills to Lua 5.1: compare blocks and closures, Hash and table semantics, method receivers, exceptions, modules, and metatable objects. Build a multi-file stock ledger and port two Ruby programs.
Ruby and Lua side by side
The same program in Ruby and in Lua, from the lessons of this course.
puts to print
Ruby puts emits lines and can expand an array into separate output lines. Lua print converts each supplied value to text, normally separating arguments with tabs and ending with a newline. Concatenate with .. when the exact spacing matters. Lua comments begin…
Ruby1puts "Hi" + ", Ada"Lua1print("Hi" .. ", Ada")nil Values and Missing Fields
Ruby Hash can contain an explicit nil value and still report that a key exists. Lua tables cannot store nil as a present value: assigning nil removes the key. A missing table lookup also yields nil. Keep false when false is meaningful data, and use a separate…
Ruby1d = {x: nil}2puts d.key?(:x)3puts d[:x].nil?Lua1local d = {x = nil}2print(d.x == nil)Ranges to Numeric for
Ruby ranges and times/upto methods yield values to blocks. Lua numeric for supplies a loop variable from a start value through an inclusive endpoint with an optional step. The bounds are evaluated when the loop begins. Use a negative step for descending…
Ruby1total = 021.upto(3) { |i| total += i }3puts totalLua1local total = 02for i = 1, 3 do total = total + i end3print(total)Methods to Functions
Ruby methods return their final expression implicitly. Lua functions require an explicit return to produce useful results; falling through returns no results, adjusted to nil in a single-value assignment. Local functions are values and can be stored or passed…
Ruby1def twice(x)2 x * 23end4puts twice(4)Lua1local function twice(x) return x * 2 end2print(twice(4))Arrays to Dense Tables
Lua uses tables for sequences and records rather than a dedicated Ruby Array type. Sequence entries conventionally start at one. Table.remove shifts later entries left, while assigning nil can leave a hole that disrupts sequence operations. Table.concat joins…
Ruby1a = ["a", "b", "c"]2a.delete_at(1)3puts a.join(",")Lua1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))sort to table.sort
Ruby sort returns a new array and uses a three-way comparison model through its ordering protocols. Lua table.sort mutates a dense sequence and accepts a Boolean less-than predicate. To preserve the input, copy the sequence before sorting. Lua does not…
Ruby1a = [3, 1, 2]2b = a.sort3puts a[0]4puts b[0]Lua1local a={3,1,2}2table.sort(a)3print(a[1])
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFrom Ruby to Lua
6 lessonsValues and Decisions
5 lessonsIteration and Flow
5 lessonsMethods, Functions, Closures
5 lessonsArrays and Hashes to Tables
5 lessonsOrdering, Modules, and Errors
5 lessonsObjects and Owned State
5 lessonsComposition and Object Lookup
6 lessonsProject: Stock Ledger
4 lessonsApply Your Ruby Experience
2 lessonsFrequently asked questions
Who is Lua for Ruby Developers for?
For people who already write Ruby and want to learn Lua. Each lesson starts from Ruby 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 Ruby basics: variables, conditions, loops, functions and collections.
How many lessons does Lua for Ruby Developers have?
Lua for Ruby Developers contains 48 interactive lessons you can complete at your own pace.
What does Lua for Ruby Developers cover?
The course is organized into chapters covering: From Ruby to Lua, Values and Decisions, Iteration and Flow, Methods, Functions, Closures, and more.
Is Lua for Ruby Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.