Examples

Lua Hello World

Basic Lua Script

Lua hello world script prints output with print function.

Introduction to Lua

Lua is a powerful, efficient, lightweight, and embeddable scripting language. It is used for a variety of applications, including gaming, web applications, and as a scripting language for other software. One of the fundamental tasks when learning a new programming language is to understand how to display output, and in Lua, this is accomplished using the print function.

Writing Your First Lua Script

Creating a "Hello, World!" script in Lua is straightforward. You only need a text editor to write your script and a Lua interpreter to run it. The script will use the print function to display the text "Hello, World!" on the screen.

Running Your Lua Script

To run your Lua script, follow these steps:

  1. Open a text editor and paste the code above.
  2. Save the file with a .lua extension, for example, hello.lua.
  3. Open a terminal or command prompt.
  4. Navigate to the directory where you saved your Lua file.
  5. Enter the command lua hello.lua and press Enter.

You should see Hello, World! printed on the screen. This confirms that your script is working correctly.

Understanding the print Function

The print function in Lua is used to output text or variables to the console. It is a built-in function that can take one or more arguments, separated by commas, and prints them to the standard output.

For example, if you want to print multiple values, you can separate them with commas:

This will output Hello, World! with a space between the words. The print function automatically adds a space between arguments.

Previous
Logging