Getting Started with Lua: Scripts, Syntax, Values, Functions and Tables
Run Your First Lua Program
The traditional first Lua program is one line:
| |
Save it as hello.lua and run it with the standalone interpreter:
| |
Lua is also designed to be embedded, so many people run scripts inside a game engine, application, or device rather than through the standalone command.
Basic syntax
Statements do not require semicolons. A line beginning with -- is a comment, and --[[ ... ]] forms a block comment.
Names are case-sensitive. A variable is global unless declared local; prefer locals to keep dependencies and scope clear.
Values
Core types include nil, boolean, number, string, function, table, thread, and userdata:
| |
Only false and nil are false in conditions. Zero and empty strings are true.
Functions and tables
The interactive interpreter is useful for experiments. Enter expressions through print, inspect values with type, and exit using the platform’s end-of-file shortcut. For real programs, organize code into modules that return explicit tables instead of relying on globals.