Lua | The School of Code

Settings

Appearance

Choose a typography theme that suits your style

Lua

Learn Lua - the lightweight, embeddable scripting language used in game development and beyond.

1

Hello World

Lua uses print() to output text. It’s a lightweight, fast, and embeddable scripting language popular in game development (Roblox, World of Warcraft addons) and embedded systems.

Example

Run this example to see how it works and then try the exercise.

example.lua
Loading...
Output
Click "Run" to see the example in action...
Exercise
main.lua
Loading...
Output
Click "Run" to execute your code...
Quiz

How do you write a single-line comment in Lua?

SUMMARY

In this section, you learned how to print output to the console. Next, you'll learn how to declare variables and work with different data types.

2

Variables and Types

Lua is dynamically typed. Variables are global by default - use local for local variables. Lua has 8 basic types: nil, boolean, number, string, function, userdata, thread, and table.

Example

Run this example to see how it works and then try the exercise.

example.lua
Loading...
Output
Click "Run" to see the example in action...
Exercise
main.lua
Loading...
Output
Click "Run" to execute your code...
Quiz

What keyword makes a variable local in Lua?

SUMMARY

In this section, you learned how to declare variables and work with different data types. Next, you'll learn how to manipulate and work with strings.

3

Arithmetic Operations

Lua offers string concatenation with .. and many string manipulation functions in the string library.

Example

Run this example to see how it works and then try the exercise.

example.lua
Loading...
Output
Click "Run" to see the example in action...
Exercise
main.lua
Loading...
Output
Click "Run" to execute your code...
Quiz

What operator concatenates strings in Lua?

SUMMARY

In this section, you learned how to manipulate and work with strings. Next, you'll learn how to perform mathematical operations.

Unlock 10 More Lessons

You've completed the free preview! Upgrade to Pro to access all 12 lessons in this course, plus advanced projects and certificates.

Locked lessons:
  • String Operations
  • Conditionals
  • For Loops
  • While Loops
  • Functions
  • Tables as Arrays
  • Tables as Dictionaries
  • Metatables and OOP
  • Final Project: Student Grade System
Hello World 1
Variables and Types 2
Arithmetic Operations 3
Unlock 10 more lessons Access all content with Pro
Upgrade
String Operations 4 Conditionals 5 For Loops 6 While Loops 7 Functions 8 Tables as Arrays 9 Tables as Dictionaries 10 Metatables and OOP 11 Final Project: Student Grade System 12

Reset Progress?

Are you sure you want to reset all progress for this course? This action cannot be undone.