Skip to content
shiprzqPublic

About

๐ŸŒ™ A friendly, hands-on guide to the Lua programming language โ€” chapters, runnable examples, exercises & a cheatsheet.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Learn Lua

๐ŸŒ™ Learn Lua

A friendly, hands-on guide to the Lua programming language โ€” from your first print to metatables and coroutines.

Lua License: MIT Examples PRs Welcome

Quick start โ€ข Chapters โ€ข Cheatsheet โ€ข Exercises โ€ข Resources


โœจ Why Lua?

Lua (Portuguese for moon) is a small, fast, embeddable scripting language created in 1993 at PUC-Rio in Brazil. The whole interpreter fits in a few hundred kilobytes, yet it powers:

Where What
๐ŸŽฎ Games Roblox (Luau), World of Warcraft add-ons, Lร–VE 2D, Defold, PICO-8
๐Ÿ› ๏ธ Tools Neovim config & plugins, Wireshark dissectors, Redis scripts
๐ŸŒ Web OpenResty / Nginx, Kong API gateway
๐Ÿ“ฆ Embedded Any C/C++ app that needs a scripting layer

If you can learn one language in a weekend, it's this one. Lua has only 8 types and ~22 keywords.

local function greet(name)
  return ("Hello, %s! ๐ŸŒ™"):format(name or "world")
end

print(greet("Lua"))   --> Hello, Lua! ๐ŸŒ™

๐Ÿš€ Quick start

1. Install Lua

OS Command
macOS brew install lua
Ubuntu / Debian sudo apt install lua5.4
Windows winget install DEVCOM.Lua or scoop install lua
Anywhere (no install) onecompiler.com/lua or the official demo

Check it worked:

lua -v
# Lua 5.4.x  Copyright (C) 1994-20xx Lua.org, PUC-Rio

2. Clone this repo and run an example

git clone https://github.com/shiprzq/learn-lua.git
cd learn-lua
lua examples/01_hello.lua

3. Or play in the REPL

$ lua
> 2 ^ 10
1024.0
> #"moon"
4

๐Ÿ“š Chapters

Work through them in order โ€” each takes about 10โ€“20 minutes and ends with a runnable example.

# Chapter You'll learn Example
1 Getting started Running Lua, comments, print 01_hello.lua
2 Variables & types local, the 8 types, nil, truthiness 02_types.lua
3 Operators & strings Math, .., string library, patterns 03_strings.lua
4 Control flow if, while, repeat, numeric & generic for 04_control_flow.lua
5 Functions Multiple returns, varargs, closures 05_functions.lua
6 Tables Arrays, dictionaries, ipairs/pairs, table.* 06_tables.lua
7 Metatables & OOP __index, operators, classes, inheritance 07_oop.lua
8 Modules require, writing your own module 08_modules.lua
9 Error handling error, pcall, assert 09_errors.lua
10 Coroutines yield/resume, generators 10_coroutines.lua
11 Gotchas & best practices 1-based indexing, globals, # with holes โ€”

๐Ÿ’ก Tip: keep the Cheatsheet open in another tab while you read.


๐Ÿงฉ Practice

Ten bite-sized exercises โ€” FizzBuzz to a tiny class system โ€” each with a solution.

lua exercises/solutions/01_fizzbuzz.lua

๐Ÿ—บ๏ธ Learning path

flowchart LR
    A[Basics<br/>ch. 1-4] --> B[Functions<br/>ch. 5]
    B --> C[Tables<br/>ch. 6]
    C --> D[Metatables & OOP<br/>ch. 7]
    C --> E[Modules<br/>ch. 8]
    D --> F[Errors & Coroutines<br/>ch. 9-10]
    E --> F
    F --> G{Pick a path}
    G --> H[๐ŸŽฎ Lร–VE / Roblox]
    G --> I[๐Ÿ› ๏ธ Neovim]
    G --> J[๐ŸŒ OpenResty]
Loading

๐Ÿ“– Where to go next


๐Ÿค Contributing

Found a typo or want to add a chapter? See CONTRIBUTING.md. Every example is run automatically by GitHub Actions, so please keep them runnable.

๐Ÿ“„ License

MIT ยฉ shipr

If this helped you, leave a โญ โ€” it helps others find it!

About

๐ŸŒ™ A friendly, hands-on guide to the Lua programming language โ€” chapters, runnable examples, exercises & a cheatsheet.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages