{}const=>[]async()letfn</>var
BasicsDevelopmentOverview

Lua is a lightweight and powerful programming language for games and automation! 🎮

Lua is a fast and flexible programming language that is used in the development of games, embedded systems and automation. In this article, you will learn how to install Lua, work with variables, loops, and conditions, and write your first programs! Everything is simple and accessible even for beginners. 🚀

К

Kodik

Author

3 min read

What is Lua? 🚀

Lua is a lightweight, fast and embedded programming language created in 1993 in Brazil. It is widely used in game development, automation and scripting. Many popular games such as Roblox, World of Warcraft, and Garry's Mod, use Lua to create scripts. 🎮

Why study Lua? 🔥

  • Simplicity: clear syntax that is easy to learn.

  • Flexibility: can be used in games, web and automation.

  • Lightness: takes up little space and is quickly executed.

  • Embeddability: Lua can be embedded in other programs.

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

How to install Lua? 💻

To work with Lua you will need:

How to check if Lua is installed? 🛠

Open the terminal and enter:

lua -v

If Lua is installed, the interpreter version will appear.

Lua Syntax Basics 📚

1. Variables 📦

In Lua, variables do not require an explicit type specification:

Example of declaring variables:

name = "Alice" -- Строка
age = 25 -- Число
pi = 3.14 -- Число с плавающей точкой

print("Name:", name, "Age:", age, "Pi:", pi)

2. Data output 📤

To display information, use print().

Example:

print("Hello, world!")

3. Conditional operators (if...else) 🧐

Allow the program to make decisions.

Example:

age = 20

if age >= 18 then
    print("You're an adult!")
else
    print("You're still a child.")
end

4. Loops (for, while) 🔄

Loops allow you to repeat actions.

Example:

for i = 1, 5 do
    print(i)
end

5. Functions 📐

Functions help to structure the code.

Example:

function square(x)
    return x * x
end

print("Square of the number 5:", square(5))

Simple projects in Lua 💡

1. Random number generator 🎲

The program generates a random number from 1 to 100.

math.randomseed(os.time()) -- Устанавливаем случайное зерно
random_number = math.random(1, 100)
print("Random number:", random_number)

2. Multiplication table 📊

The program displays a multiplication table from 1 to 10.

for i = 1, 10 do
    for j = 1, 10 do
        io.write(i * j, "\t")
    end
    print()
end

3. Counting the number of characters in a string 🔢

The program counts the characters in the string.

text = "Hello, Lua!"
print("Number of characters:", #text)

4. Checking the number for evenness 🔍

The program determines whether the number is even.

number = 42

if number % 2 == 0 then
    print(number .. " - even number")
else
    print(number .. " - odd number")
end

5. Calculating the factorial of a number 🎯

This code calculates the factorial of a given number.

function factorial(n)
    if n == 0 then
        return 1
    else
        return n * factorial(n - 1)
    end
end

print("Factorial 5:", factorial(5))

Conclusion 🎉

Lua is a powerful programming language that is easy to learn. We have analyzed its basics: variables, input/output, conditions, loops and functions. Now you can write your first programs! 🚀

The more you practice, the better your code becomes. Experiment, try new tasks and master programming! Good luck learning Lua! 😊

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card