HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to LuaVariablesNumbers & MathStringsTablesConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Table
🔁 Condition & Loop
🧩 Function
Lua›Introduction to Lua

Introduction to Lua

First step into the simple scripting language Lua: printing with print, variables, and concatenation with ..

Simple enough for a 5-year-old to understand

Print with print

Your first program
1
print("Hello!")
Prints to the screen and moves to the next line.
Output / InputPrints to the screen and moves to the next line.
Output / Input
💡 Hint: Lua is very simple: semicolons are not required.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.What is used to concatenate two strings in Lua?
2.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

Lua is a small and fast scripting language developed in Brazil in 1993. Its name means "moon" in Portuguese. Its design goal was to be embeddable inside other programs, and it achieved this goal abundantly.

Today you mostly see Lua in games: Roblox, World of Warcraft addons, and many game engines use Lua as a scripting language. It is also popular outside of gaming — Nginx configuration, embedded devices, and Redis scripts are a few examples.

The entirety of Lua is a library of a few hundred kilobytes, and the number of keywords you need to learn is around twenty. This simplicity is intentional: the language is built around a single data structure, the table, and everything else is built on top of it.

What you will learn

  • how a Lua program works
  • printing to the screen with print
  • Writing comment lines
  • that semicolons are not required
  • where Lua is used

Who is this for?

  • Those who want to write game scripts
  • Those looking for a lightweight language in embedded systems
  • Those who want a simple language as a first programming language

When to use?

Lua is the ideal choice when you want users to be able to change an application's behavior: game plugins, configuration scripts, and rule engines are written this way.

It is not suitable for large-scale application development; its standard library is small and it has no type checking.

Common mistakes

Wrong

// This is a comment
print("Hello")

Comment lines in Lua start with two dashes; double slashes are a habit from other languages and will throw a syntax error in Lua. For multi-line comments, two dashes and double square brackets are used.

Correct

-- This is a comment
print("Hello")

Wrong

Print("Hello")

Lua is case-sensitive and the function name is lowercase print. This code will throw an "attempt to call a nil value (global 'Print')" error. The error message is interesting: Lua treats an undefined name as nil, so instead of saying "there is no such function", it says "attempt to call a nil value".

Correct

print("Hello")

Wrong

print("Number: " + 5)

In Lua, the string concatenation operator is two dots, not a plus sign. The plus sign tries to perform numeric addition, and since the string cannot be converted to a number, you get an "attempt to perform arithmetic on a string value" error. This distinction is the most common pitfall for beginners in Lua.

Correct

print("Number: " .. 5)

Frequently asked questions

What is the difference between Lua and LuaJIT?

LuaJIT is an alternative just-in-time compiling interpreter for Lua and is noticeably faster for most tasks. The language is the same, but LuaJIT is based on the Lua 5.1 syntax; some features of newer versions are missing in LuaJIT.

Should I use semicolons?

Not necessary. Lua treats the end of a line as the end of a statement. Writing semicolons is valid and they are used as separators when putting multiple statements on the same line, but they are rarely seen in everyday code.

Why do indices start at one in Lua?

The designers adapted the counting habit thinking that mathematicians and engineers would also use the language. This choice is debated today, but it is consistent everywhere in the language: tables, strings, and the standard library all start counting from one.

Summary

Comments start with two dashes.

The language is case-sensitive.

String concatenation is done with two dots.

Semicolons are not required.

Lua was designed as an embedded scripting language.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code