Skip to content
    Lua PlaygroundLua 5.3 · Fengari
    Output

    Lua Compiler Online: Run Lua 5.3 Scripts in Your Browser

    This Lua compiler runs your scripts with Fengari, a reimplementation of the Lua 5.3 virtual machine and standard library in JavaScript. Your code is parsed, compiled to Lua bytecode and executed inside your browser tab, so there is nothing to install and nothing is uploaded to a server. Use it to run Lua online while you learn the language, to check how tables, metatables, closures, coroutines and string patterns behave, or as an online Lua compiler for sharing a runnable snippet by link. _VERSION reports "Lua 5.3", and the base, string, table, math, utf8, coroutine, os and debug libraries are loaded.

    How to use the Lua online compiler

    1. Write Lua in the editor, or load one of the Samples: tables, coroutines, metatables, string patterns or a module pattern.
    2. Press Run. A new Lua state is created, the standard libraries are opened, and your script runs from the first line.
    3. Read the output panel. print separates its arguments with tabs and ends with a newline, while io.write prints exactly what you pass it.
    4. If the script fails, the panel shows the output produced so far, followed by the error and its line number in main.lua.
    5. Press Share to copy a link. The script travels inside the URL, so there is nothing to save or upload.

    Features

    • Lua 5.3 language and standard library via Fengari (Lua 5.3 VM in JavaScript)
    • Integer and float subtypes, the // operator, bitwise operators, goto and utf8
    • print and io.write captured in the output panel, using tostring rules
    • Syntax and runtime errors reported with line numbers
    • A fresh Lua state for every run, so globals never leak between runs
    • The VM is bundled with the page, so Run needs no extra download
    • Six sample programs to start from
    • Shareable links with the script compressed into the URL

    What works and what doesn’t

    • Integers are 32-bit. math.maxinteger is 2147483647, math.maxinteger + 1 wraps to -2147483648, and integer literals beyond that range become floats, whereas the C implementation of Lua 5.3 uses 64-bit integers.
    • Lua 5.4 syntax is not supported: the <const> and <close> local attributes are syntax errors.
    • Only part of the io library exists. io.write and io.stdout:write print to the output panel, but io.read, io.open and io.lines are missing, so there is no keyboard input or file access.
    • require cannot load modules, because there is no file system and no LuaRocks. Keep modules as local tables in the same script.
    • This is not Luau or LuaJIT. Roblox syntax such as type annotations, += and continue is rejected, and LuaJIT's ffi and bit libraries do not exist.
    • Scripts run on the page's main thread, so an infinite loop freezes the tab until the browser offers to stop the page.

    Example programs

    Metatables: a vector type with operators

    Metamethods give a table arithmetic, equality and a readable tostring. print converts each argument with tostring, so the vector is printed through __tostring. Expected output: (3, 4), 5.0 and true, separated by tabs. The 5.0 shows Lua 5.3's separate float subtype.

    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.__eq(a, b) return a.x == b.x and a.y == b.y end
    function Vector:__tostring() return ("(%g, %g)"):format(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(0, 0)
    print(v, v:length(), v == Vector.new(3, 4))

    Coroutines as generators

    coroutine.wrap turns a function that yields into an iterator for a generic for loop. This one produces every third number from 1 to 10, and the loop collects their squares. Expected output: 1, 16, 49, 100.

    local function range(n, step)
      return coroutine.wrap(function()
        for i = 1, n, step or 1 do coroutine.yield(i) end
      end)
    end
    
    local squares = {}
    for i in range(10, 3) do
      squares[#squares + 1] = i * i
    end
    print(table.concat(squares, ", "))

    Integers, floor division, bitwise operators and patterns

    Lua 5.3 features in a few lines: // floor division, math.type, bitwise operators and gmatch captures. math.maxinteger prints 2147483647 because Fengari uses 32-bit integers, where the C implementation prints 9223372036854775807. The loop splits a log line into date, level and message.

    print(7 // 2, 7 / 2, 7 % 3)
    print(math.type(1), math.type(1.0), math.maxinteger)
    print(0xF0 | 0x0F, 1 << 8, ~0)
    
    local log = "2026-09-14 ERROR disk full; 2026-09-14 WARN retrying"
    for date, level, msg in log:gmatch("(%d+%-%d+%-%d+) (%u+) ([^;]+)") do
      print(date, level, msg)
    end

    Frequently asked questions

    Which Lua version does this Lua online compiler run?

    Lua 5.3. Fengari reimplements the Lua 5.3 virtual machine and standard library in JavaScript, and _VERSION prints "Lua 5.3". Integer and float subtypes, floor division with //, bitwise operators, goto and the utf8 library all work. Lua 5.4 additions such as <const> and <close> do not, and integers are 32-bit.

    Is Lua a compiled language?

    Lua is usually called an interpreted language, but it has a compile step. The reference implementation compiles source code to bytecode, which the luac tool can save to a file, and its virtual machine then runs that bytecode. Fengari, used here, does the same in JavaScript: it compiles each script to Lua bytecode and runs it on its own VM.

    Can I test Roblox scripts here?

    Only the plain Lua parts. Roblox uses Luau, a language derived from Lua 5.1 with additions such as type annotations, compound assignment like += and the continue keyword. Those are syntax errors in Lua 5.3, and Roblox objects like game and workspace do not exist here, so test Roblox code in Roblox Studio.

    Can I use require, LuaRocks or files?

    No. There is no file system and no package manager, so require cannot find module files and LuaRocks packages cannot be installed. io.read, io.open and io.lines are missing too. The standard libraries are already loaded without require, and your own modules can live as local tables in the same script.

    How are Lua errors reported?

    A syntax error stops the script before it starts, and the panel shows the parser message with a line number, such as main.lua:1: unexpected symbol near '<'. A runtime error, including one raised with error(), stops execution and appears after the output printed up to that point, so you can see how far the script got.

    Is my Lua code sent to a server?

    No. The Fengari virtual machine is part of the page's JavaScript, so your script is compiled and run inside your browser tab without being sent to WebFiddle. It leaves your device only when you press Share and send someone the link, which stores the code compressed in the URL.

    Is this useful for learning Lua for games or embedded scripting?

    Yes, for the core language: tables, metatables, closures, coroutines and string patterns behave as the Lua 5.3 manual describes. Many engines embed Lua 5.1 or LuaJIT instead, which differ in details such as integer division and bit operations, and host APIs like LÖVE's love module are not available here.

    Embed this sandbox

    Paste this iframe into any web page and readers can run code without leaving it. The snippet travels in the URL, so there is nothing to host and no account to create. Open the sandbox, write your example, press Share, then append that link’s query string to the embed URL to preload it.

    <iframe src="https://webfiddle.xyz/embed/lua" width="100%" height="480" loading="lazy"
            style="border:1px solid #ddd;border-radius:8px"
            title="WebFiddle lua sandbox"></iframe>
    Preview the embed

    Related articles

    Related sandboxes

    Official documentation