Skip to main content
China-Pakistan Economic Corridor

4.3. Lua basic syntax

Release time :2025-10-25 12:06:05 UTC

Page Views: 0 views

Lua is very easy to learn, and we can create the first Lua program!

4.3.1. The first Lua program #

Interactive programming #

Lua provides an interactive programming mode. We can enter the program on the command line and see the effect immediately.

Lua interactive programming mode can be realized by command lua -i or lua to enable:

$ lua -i
$ Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
>

On the command line, enter the following command:

> print("Hello World!")

Then we press the enter key and the output is as follows:

> print("Hello World!")
Hello World!
>

Script programming #

We can save the Lua program code to a lua at the end of the file, and execute, this pattern is called scripted programming, such as we store the following code in a file named hello.lua in the script file:

Article link : 4.3. Lua basic syntax