How to use the online Lua compiler
- Write or paste a Lua script into the editor. Reset example restores the starter code.
- Press Run or use Ctrl + Enter (⌘ + Enter on a Mac).
- Everything you pass to
print()appears in the Output panel. Like the standard interpreter, multiple arguments are separated by tabs, andnilis printed asnil. Runtime and syntax errors are highlighted along with the line number. - Choose a time limit of 5, 15 or 60 seconds. A script that runs too long is stopped automatically, and Stop ends it immediately.
The Lua runtime is small, well under 1 MB, so the page is ready to run almost instantly. Use Copy or main.lua to save your script.
Your script runs in a Web Worker inside your browser. It is never uploaded and is not stored on our servers. The editor remembers your last code in your browser's local storage, and in no other place.
What's supported
The compiler runs Lua 5.4 through wasmoon, a WebAssembly build of the reference Lua interpreter written in C. Your code is executed by real Lua, not by a translation into JavaScript.
- The Lua 5.4 language: integer and float subtypes, integer division (
//), bitwise operators,goto, and the<const>and<close>local attributes. - Standard libraries:
string(including Lua patterns andstring.format),table,math,utf8andcoroutine. - Closures, metatables and coroutines, so you can practise object-oriented and generator-style Lua.
Limitations:
- Use
print()for output. Output is captured fromprint, so use it rather thanio.write. - No standard input, network access or real files. Put your test data directly in the script.
- No C modules or LuaRocks. Only pure Lua code in the editor can run.
- Each run gets a fresh Lua state, so globals from the previous run are cleared.
Lua quick reference
local Account = {}
Account.__index = Account
function Account.new(owner, balance)
return setmetatable({ owner = owner, balance = balance or 0 }, Account)
end
function Account:deposit(v)
self.balance = self.balance + v
end
local acc = Account.new("Ada")
acc:deposit(50)
print(acc.owner, acc.balance) --> Ada 50
for word in ("one two three"):gmatch("%a+") do
print(#word, word:upper())
end
print(7 // 2, 7 / 2) --> 3 3.5
| Task | Syntax |
|---|---|
| Local variable | local x = 10 |
| Concatenate strings | "a" .. "b" |
| Length of a string or list | #t |
| Not equal | a ~= b |
| Numeric loop | for i = 1, 10, 2 do ... end |
| Iterate a list / a table | for i, v in ipairs(t) / for k, v in pairs(t) |
| Format a number | string.format("%.2f", n) |
Tips
- Lua arrays start at index 1, not 0, and
#is only reliable for sequences withoutnilholes. - Declare variables with
local. Without it, a variable is global, which is slower and a common source of bugs. - Only
nilandfalseare falsy.0and the empty string are true in Lua. - Lua patterns look like regular expressions but are simpler, and use
%instead of a backslash, as in%d+. For full regular expressions in other languages, try the regex tester.
pairs, or use table.concat(list, ", ") for a list of strings and numbers. Passing the table itself to print(t) does not list its contents.Frequently asked questions
Which Lua version does this use?
Lua 5.4. Run print(_VERSION) to confirm. Code written for Lua 5.3 almost always works unchanged, while Lua 5.1 or LuaJIT code may need small changes, for example replacing unpack with table.unpack.
Can I test Roblox or LÖVE scripts here?
You can test plain Lua logic, such as functions, tables, string handling and maths. Engine APIs like Roblox services (Roblox uses its own Luau dialect) or LÖVE's love.* functions do not exist here.
Why doesn't io.read work?
The compiler has no interactive standard input. Define your test values as variables at the top of the script.
What other languages can I run online?
The online Python compiler and the online Ruby compiler also run entirely in your browser.