Menu
CoddyTech
Course

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.

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

    Ruby
    1puts "Hi" + ", Ada"
    Lua
    1print("Hi" .. ", Ada")
  2. 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…

    Ruby
    1d = {x: nil}2puts d.key?(:x)3puts d[:x].nil?
    Lua
    1local d = {x = nil}2print(d.x == nil)
  3. 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…

    Ruby
    1total = 021.upto(3) { |i| total += i }3puts total
    Lua
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. 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…

    Ruby
    1def twice(x)2  x * 23end4puts twice(4)
    Lua
    1local function twice(x) return x * 2 end2print(twice(4))
  5. 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…

    Ruby
    1a = ["a", "b", "c"]2a.delete_at(1)3puts a.join(",")
    Lua
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. 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…

    Ruby
    1a = [3, 1, 2]2b = a.sort3puts a[0]4puts b[0]
    Lua
    1local a={3,1,2}2table.sort(a)3print(a[1])

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Apply Your Ruby Experience

2 lessons

More courses for Ruby developers

Learn Lua from another language

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

Coddy programming languages illustration

Start Lua for Ruby Developers for free

Get started