Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Lua is a lightweight scripting language created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes at PUC-Rio in Brazil. Its name means "moon" in Portuguese, and its design goal is to be a small, fast, embeddable language that host programs can extend. A single data structure -- the table, an associative array -- underpins its arrays, objects, and modules, which keeps the core tiny. That embeddability made Lua the scripting layer inside games such as Roblox and World of Warcraft, and inside Redis, Nginx, and countless IoT and embedded devices. On XCODX it runs on a standalone Lua interpreter with the standard library, so you can learn tables, closures, and string patterns without embedding it in anything.
-- Tables are Lua's one data structure: array and map in one
local fruits = {"apple", "banana", "cherry"}
for i, name in ipairs(fruits) do
print(i .. ": " .. name)
end
-- Count letters in a word using a table as a map
local counts = {}
for letter in ("banana"):gmatch("%a") do
counts[letter] = (counts[letter] or 0) + 1
end
for letter, n in pairs(counts) do
print(letter .. " appears " .. n .. " time(s)")
end
Lua's strengths are a tiny footprint, fast execution, and an exceptionally clean C interoperability layer, which is why it is embedded as the scripting engine in games, Redis, Nginx/OpenResty, and embedded firmware rather than used on its own. Choose it when a larger application needs a small, safe language to expose to users or to configure behaviour, or when learning programming concepts with minimal syntax. It is a weaker choice for large standalone applications or data science, where its deliberately small standard library and thin package ecosystem mean more work than Python.
No. The sandbox runs a plain Lua interpreter with the standard library only, and there is no luarocks and no network access to download modules. Built-in libraries such as string, table, math, io, and os are always available, but third-party rocks are not. Install Lua and LuaRocks locally if you need external modules.
Call io.read() to read one line as a string, or io.read("*n") to read a number and io.read("*a") to read everything. In XCODX you type into the live terminal or the Stdin Box and press Enter, and Ctrl+D closes the stream so a loop like for line in io.lines() do ... end can finish. Wrap a value in tonumber() if you read a number as text.
Tables are Lua's only built-in data structure and serve as arrays, dictionaries, objects, and modules all at once. You index them with almost any value -- {1, 2, 3} uses integer keys while {name = "Lua"} uses string keys -- and metatables let you add object-oriented behaviour. Mastering tables is most of learning Lua, and they work fully in the sandbox.
By design Lua indexes sequences from 1 rather than 0, matching how the language was originally used for data description. The ipairs iterator and the length operator # both assume this 1-based convention. It trips up newcomers from C-style languages, so remember that t[1] is the first element, not t[0].
Yes. Lua has a very small syntax, dynamic typing, and just a handful of core concepts -- variables, functions, and tables -- so it is quick to pick up. The main surprises are 1-based indexing and that undeclared variables are global by default, so use local for locals. The XCODX interpreter is a low-friction place to try it with no setup.
Both are dynamically typed scripting languages, but Lua is deliberately minimal and built to be embedded inside other programs, while Python is a batteries-included general-purpose language with a huge standard library. Lua starts faster and has a tiny footprint; Python ships far more built-in modules and a vast third-party ecosystem. For embedding in a game or device you pick Lua; for standalone apps and data work you usually pick Python.
main.lualuaio.read()print("Hello from Lua!")
print("Welcome to XCODX Online Compiler!")
local message = "Lua is fun!"
print(message)