- Lua Tutorial
- Lua - Home
- Lua Basics
- Lua - Overview
- Lua - Environment
- Lua - Basic Syntax
- Lua - Comments
- Lua - Print Hello World
- Lua - Variables
- Lua - Data Types
- Lua - Operators
- Lua - Loops
- Lua - Decision Making
- Lua - Functions
- Lua - Date and Time
- Lua Strings
- Lua - Strings
- Lua - String Concatenation
- Lua - Loop Through String
- Lua - String to Int
- Lua - Split String
- Lua - Check String is NULL
- Lua Arrays
- Lua - Arrays
- Lua - Multi-dimensional Arrays
- Lua - Array Length
- Lua - Iterating Over Arrays
- Lua - Slicing Arrays
- Lua - Sorting Arrays
- Lua - Merging Arrays
- Lua - Sparse Arrays
- Lua - Searching Arrays
- Lua - Resizing Arrays
- Lua - Array to String Conversion
- Lua - Array as Stack
- Lua - Shuffling Arrays
- Lua Iterators
- Lua - Iterators
- Lua Lists
- Lua - Searching in Lists
- Lua Modules
- Lua - Modules
- Lua - Namespaces
- Lua Metatables
- Lua - Metatables
- Lua Coroutines
- Lua - Coroutines
- Lua File Handling
- Lua - File I/O
- Lua Advanced
- Lua - Error Handling
- Lua - Debugging
- Lua - Garbage Collection
- Lua - Object Oriented
- Lua - Web Programming
- Lua - Database Access
- Lua - Game Programing
- Lua Useful Resources
- Lua - Quick Guide
- Lua - Useful Resources
- Lua - Discussion
Lua - Comments
Comments are a set of commands that are ignored by the compiler. They are used in a scenario where you want to attach a note to your code or a section of code so that when you visit it later, you can recall it easily. The comment statements are usually ignored during the execution of the program.
There are two types of comments in Lua −
Single-line comments
Multi-line comments
Multi-line comments are also known as block comments in Lua.
Single-Line Comment
A single-line comment in Lua starts with a double hyphen (--) and runs until the end of the line.
Syntax
-- this is a comment
Let's consider an example where we write multiple single-line comments and then deliberately write invalid codes inside them and see what happens.
Example
Consider the example shown below −
-- z = 10 print(z) x = 11 -- print(x) -- ans
Notice that on the last line, we are declaring a global variable without an assignment which is illegal according to Lua, but since we are doing it inside a comment, it will be ignored by Lua.
Output
nil
Multi-Line Comments
Multi-Line comments, also known as block comments in Lua, make use of a special syntax.
Syntax
--[[ this is a comment --]]
Let's create an example where we write two block comments, one of them is a valid comment and the other one is not a valid block comment.
Example
Consider the example shown below −
--[[
print(110)
--]]
---[[
print("str")
--]]
In the above example, the second section of code looks like a valid block level comment, but if we look closely, then we will notice that it isn't.
Output
str