FizzBuzz with a numeric for
for i = 1, 15 do
local word = (i % 3 == 0 and "Fizz" or "") .. (i % 5 == 0 and "Buzz" or "")
print(word ~= "" and word or i)
end
Write Lua and run it right here. The Lua interpreter runs inside your browser, so nothing you type is uploaded.
Ready
-- io.read() reads one line from the input box.
local name = io.read() or "world"
print("Hello, " .. name .. "!")
for i = 1, 3 do
print(i .. " squared is " .. i * i)
end
Type the input before you run. Each io.read() call reads the next line.
Press Run or Ctrl+Enter to see the output here.Runs in your browser with Lua 5.4 (wasmoon 1.16.0). Your code is not sent to a server.
Runtime: Lua 5.4 (wasmoon 1.16.0)
Lua runs as the reference Lua 5.4 interpreter compiled to WebAssembly, packaged by wasmoon 1.16.0. The runtime is small — about 0.1 MB — so even the first run starts almost at once. The standard libraries are there: string with Lua patterns, table, math, utf8, os.time and os.date, and coroutine. Each run gets a brand-new Lua state, and errors come with a stack traceback that points at main.lua.
Everything happens on your device. The code you write is never uploaded, logged or stored on a server. Each run stops after 10 seconds and keeps up to 100,000 characters of output, so an endless loop cannot freeze the page.
This is plain Lua 5.4, not LuaJIT, Luau or a game engine, so their extra libraries are missing. io.open and require cannot reach files on your computer or modules from LuaRocks. print, io.write, io.read and io.lines() are wired to this page's output and input box, and os.exit ends the program without closing anything else.
Open an example in the editor above, change it and run it. Opening an example does not run it.
for i = 1, 15 do
local word = (i % 3 == 0 and "Fizz" or "") .. (i % 5 == 0 and "Buzz" or "")
print(word ~= "" and word or i)
end
local fruits = { "apple", "banana", "cherry" }
table.insert(fruits, "date")
for index, fruit in ipairs(fruits) do
print(index, fruit)
end
local stock = { apple = 3, banana = 0, cherry = 12 }
local names = {}
for name in pairs(stock) do names[#names + 1] = name end
table.sort(names)
for _, name in ipairs(names) do
print(name, stock[name] > 0 and "in stock" or "sold out")
end
local function counter(step)
local count = 0
return function()
count = count + step
return count
end
end
local byOne, byTen = counter(1), counter(10)
print(byOne(), byOne(), byOne())
print(byTen(), byTen())
local Vector = {}
Vector.__index = Vector
function Vector.new(x, y)
return setmetatable({ x = x, y = y }, Vector)
end
function Vector.__add(a, b) return Vector.new(a.x + b.x, a.y + b.y) end
function Vector:__tostring() return "(" .. self.x .. ", " .. self.y .. ")" end
function Vector:length() return math.sqrt(self.x ^ 2 + self.y ^ 2) end
local v = Vector.new(3, 4) + Vector.new(1, 2)
print(v, v:length())
-- Read numbers from the input box until it runs out.
local total, count = 0, 0
for line in io.lines() do
local n = tonumber(line)
if n then
total, count = total + n, count + 1
end
end
print(string.format("count %d, sum %g, average %.2f", count, total, total / count))
Input
4 8 15 16 23 42
Programs here do not stop and wait for you to type while they run. Everything your program reads comes from the input box, which you fill in before pressing Run.
io.read() reads the next line, io.read("n") reads a number and io.read("a") reads everything that is left. for line in io.lines() do … end loops over every line of the input box. When the input runs out, io.read returns nil.
Your latest Lua code and input are saved automatically in this browser, so they are still here when you come back. Nothing is saved on a server.
Share creates a link that carries your code inside the address itself, compressed after the # sign. Whoever opens it sees your code in the editor, and it only runs when they press Run.
| Keys | Action |
|---|---|
| Ctrl+Enter | Run the code |
| Ctrl+/ | Comment or uncomment the line |
| Tab · Shift+Tab | Indent or outdent the selection |
| Ctrl+F | Find and replace in the code |
| Ctrl+Z · Ctrl+Shift+Z | Undo / redo |
| Esc → Tab | Leave the editor with the keyboard |
On a Mac, use ⌘ instead of Ctrl.
It is standard Lua 5.4, the same language the official interpreter runs. It is not LuaJIT, so the ffi and bit libraries from LuaJIT are not available; integer division, bitwise operators and the utf8 library from Lua 5.4 are.
The plain Lua parts will run — tables, functions, string handling and your own logic. The APIs those programs provide, such as Roblox services, love.graphics or vim.api, do not exist here, so code that calls them will stop with an error.
The Lua interpreter is tiny: about 0.1 MB to download, compared with around 12 MB for Python. It is ready a moment after you open the page, and each run creates a fresh Lua state in a few milliseconds.
Yes. There is no account, no sign-up and no daily limit. The only limit is that a single run stops after 10 seconds.
No. The Lua runtime is downloaded into your browser and your code runs there, on your device. The site only serves the page and the runtime files; it never receives the code you write or the input you give it.
In this browser's local storage, one draft per language. It stays until you clear this site's data, and it is not synced to other devices. Use a share link to move code somewhere else.
Press Share and send the copied link. The code is compressed into the part of the link after #, which browsers never send to a server. Very long programs do not fit in a link, and the page will tell you when that happens.
Yes. It runs in any current mobile browser. On a slow connection the first run takes longer because the runtime has to be downloaded once.