OneCompiler

Lua

A hands-on introduction to Lua for beginners. Learn variables, loops, functions, tables, strings and error handling, with a coding exercise after every lesson.

8 sections·37 items·Beginner
This course includes
  • 37 practice problems
  • 37 lessons
  • Free — runs in your browser, no setup

What you'll learn

Write and run Lua programs
Use variables, numbers, strings, booleans and nil
Control your program with if statements and loops
Write functions, pass them around and use closures
Use tables as lists, dictionaries and objects
Search and change text with string functions and patterns
Handle errors with pcall and make objects with metatables

Syllabus

About this course

Lua is a small programming language that is often built into other programs. Many games use it for their scripts. World of Warcraft add-ons are written in Lua, and Roblox uses a version of Lua called Luau. The Neovim editor uses Lua for its settings and plugins, and Redis can run Lua scripts on its server.

It is also a good first language. Lua has only a few rules, and one data structure, the table, does the work of lists, dictionaries and objects. This course starts with your first print and goes through variables, loops, functions, tables, strings and error handling. Each lesson is short and ends with a coding exercise that you run in the browser.

You don't need any programming experience. If you already know another language, look out for the places where Lua is different: lists start at 1, only false and nil count as false, and there is no continue. The lessons point these out when they come up.