Lua
v5.4.4
Lua
v5.4.4
Lua is a lightweight, high-level scripting language created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes at PUC-Rio in Brazil. It is designed to be small, fast, portable, and easily embeddable, with a simple syntax, dynamic typing, automatic memory management, and powerful tables as its core data structure.
Lua is widely used as an embedded scripting language in games (such as those built with the LÖVE framework and Roblox), applications, and configuration systems. It also powers tools like Redis scripting and Neovim configuration. Its minimal footprint and clean C API make it a popular choice for extending software with scripting.
print("Hello, World!")io.write("Enter your name: ")
local name = io.read()
print("Hello, " .. name .. "!")local fruits = {"apple", "banana", "cherry"}
for i, fruit in ipairs(fruits) do
print(i .. ": " .. fruit)
endlocal function factorial(n)
if n <= 1 then return 1 end
return n * factorial(n - 1)
end
print(factorial(5))local ages = {alice = 30, bob = 25}
ages.carol = 28
for name, age in pairs(ages) do
print(name .. " is " .. age)
endlocal function risky(x)
if x < 0 then error("negative not allowed") end
return math.sqrt(x)
end
local ok, result = pcall(risky, -1)
if ok then
print("Result: " .. result)
else
print("Error: " .. result)
endlocal s = "Hello, Lua"
print(#s) -- length
print(string.upper(s)) -- uppercase
print(s:sub(1, 5)) -- substring
print(string.format("%d items", 3))local nums = {5, 2, 8, 1, 9}
table.sort(nums)
for _, n in ipairs(nums) do
io.write(n .. " ")
end
print()local function make_counter()
local count = 0
return function()
count = count + 1
return count
end
end
local next = make_counter()
print(next())
print(next())
print(next())local Animal = {}
Animal.__index = Animal
function Animal.new(name)
return setmetatable({name = name}, Animal)
end
function Animal:speak()
return self.name .. " makes a sound"
end
local a = Animal.new("Rex")
print(a:speak())Yes. CompileBytes runs your Lua scripts in the browser with no local interpreter installation needed.
This compiler runs Lua 5.4.4, so syntax and standard library functions available in the 5.4 series are supported.
Use io.read() to read a line from standard input. Enter your text in the input/stdin panel before running.
Yes, running Lua on CompileBytes is completely free and requires no signup.
Yes—Lua tables used as arrays conventionally start at index 1, not 0, which is important to remember when iterating with ipairs or numeric loops.