Hello World in Lua
Welcome to Lua Programming
Welcome to your first step into the world of Lua programming! In this course, you will learn the basics of coding using Lua, a simple yet powerful language used in games, automation, and more. If you are new to programming, don’t worry — this lesson is designed to be beginner-friendly and will guide you every step of the way.
What You'll Learn
In this lesson, you will write your very first Lua program. This is a classic tradition in programming, often called the "Hello, World!" program. It’s a simple way to make sure everything is working and to get comfortable with the basic structure of a Lua script.
Here’s what the code looks like:
When you run this code, you will see the following output:
Notice that the quotation marks (") are not printed — they are used in the code to tell Lua where the text starts and ends, but only the text inside them appears in the output.
Let’s break it down:
printis a function in Lua that displays text on the screen.- The text inside the quotation marks (
"Hello, World Traveller!") is what will be shown when you run the program, but the quotation marks themselves will not appear in the output.
Printing Multiple Items
In Lua, you can print more than one thing at a time by separating them with commas inside the print function. Lua will automatically add a space between each item in the output.
For example:
This will display:
You can use this feature to print several words, numbers, or even variables at once. Just separate each item with a comma, and Lua will handle the rest!
Adding Comments in Lua
As you start writing code, it's helpful to leave notes for yourself or others. In Lua, you can add comments to explain what your code does. Comments are ignored by the computer when your program runs.
To write a comment in Lua, start the line with two dashes (--). For example:
Use comments to make your code easier to understand!
