How to Use the Lua Compiler

To use the Lua Compiler, follow these steps:

  1. In the code editor, write your Lua code.
  2. Click the "RUN" button to compile and run your code.
  3. The output will be displayed in the console below the code editor.

Taking Inputs

In Lua, you can take inputs from the user in various ways. Here are some examples:

String Input

io.write("Enter a string: ")
local input =
print("You entered: " .. input)

Number Input

io.write("Enter a number: ")
local num ="*n")
print("You entered: " .. num)

Multiple Inputs

io.write("Enter two numbers separated by space: ")
local num1, num2 ="*n", "*n")
print("You entered: " .. num1 .. " and " .. num2)

Importing Libraries

Lua has a rich set of built-in libraries that can be used in your programs. Here are some examples:

Using the Math Library

local result = math.sqrt(25)
print("Square root of 25 is " .. result)

Using the Table Library

local tbl = {5, 2, 8, 7, 1}
for i, v in ipairs(tbl) do

Syntax 101

Lua is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Here's a primer on the major syntax basics of Lua:


Variables in Lua can be either global or local.

name = "John Doe" -- Global variable
local age = 25 -- Local variable

Control Structures

Lua includes control structures such as if, else, for, while, and repeat.

-- If-Else
if age > 18 then

-- For loop
for i = 0, 5 do

-- While loop
local i = 0
while i < 5 do
    i = i + 1

-- Repeat loop
local i = 0
    i = i + 1
until i >= 5


Functions in Lua are first-class values and can be stored in variables, passed as arguments, and returned as results.

function greet(name)
    print("Hello, " .. name)

greet("John Doe") -- Calls the function with "John Doe" as the argument


Tables in Lua are the main (and only) data structuring mechanism, and can be used to represent arrays, sets, records, graphs, trees, etc.

local person = {
    name = "John Doe",
    age = 25,
    greet =

        print("Hello, " ..

person:greet() -- Calls the greet method of the person table

Lua Online Test

A Lua online test is an effective way to assess an individual's Lua programming skills. These tests typically include a mix of theoretical questions and practical coding challenges. By attempting these tests, candidates can demonstrate their understanding of Lua concepts, their problem-solving abilities, and their proficiency in writing efficient code. Lua online tests are commonly used in technical interviews, coding bootcamps, and online learning platforms to gauge a learner's understanding and proficiency in Lua.