DevTools Logo

Lua Playground

Lua Playground

Run a Lua 5.4 subset in your browser with an instruction budget and clear error output.

Runs in your browser
Loops are interrupted when the budget is exhausted.
Try an example

Lua source

Console

No output yet

Write Lua or load an example, then press Run.

Examples

Loop sum

Input
for i = 1, 10 do sum = sum + i end
Output
55

Numeric for loops support an optional step as the third bound.

Unicode

Input
print("Grüße — 日本語")
Output
Grüße — 日本語

Strings are treated as byte-exact text; no transliteration is applied.

Budget

Input
while true do print("tick") end
Output
Execution budget exceeded

The interpreter stops at the configured step count and reports how many steps ran.

About this tool

Lua Playground is a small, dependency-free scratchpad for learning and checking Lua code. It executes a useful subset of Lua 5.4 directly in JavaScript: local variables, reassignment, arithmetic and string concatenation, comparisons, if/elseif/else, while and numeric for loops, break, user-defined functions with return values, and a handful of built-in helpers.

Every run is bounded. An instruction budget (100,000 steps by default) interrupts runaway loops and reports the interruption together with the number of steps used; output is capped and a truncation notice is appended if a script prints too much. Syntax errors such as an unclosed string are reported with the source line so you can fix them directly in the editor.

The console keeps captured output separate from problems. Built-ins include print, tostring, tonumber, type, math.floor/ceil/abs/sqrt/max/min and string.len/upper/lower/rep/sub. Unicode strings pass through unchanged, which makes the playground handy for quick text exercises as well as algorithm drills.

Unlike wasm-based playgrounds there is no engine download and no server round trip: the interpreter is plain TypeScript running in your tab. That also defines its boundary — this is a teaching subset, not a complete Lua runtime with io, os, require or tables.

What this tool does not do

  • The interpreter implements a subset of Lua; tables, metatables, coroutines, modules and most of the standard library are not available.
  • Scripts run on the main thread; extremely large budgets can make the page busy until the run completes.
  • Numbers use JavaScript IEEE-754 semantics, so integer/float distinctions from Lua 5.4 are not preserved.
  • Output is capped and long strings may be truncated; the cap is configurable only through the library API, not the UI.
  • There is no shared state between runs and no persistence; Reset clears the draft and console.

How to use this tool

  1. Write or load a script

    Type Lua in the source pane or choose an example: hello world, a for loop, recursive fibonacci, Unicode strings or an intentional infinite loop.

  2. Set the instruction budget

    Leave the default 100,000 steps for normal scripts. Lower it to see how the interrupt behaves, or raise it for larger computations.

  3. Run

    Press Run (or Mod+Enter). Output appears in the console pane; syntax and runtime errors appear with a line number in the Problems surface.

  4. Copy or reset

    Copy the captured output, download it as a text file, or reset the playground to clear both source and result.

Use cases

Learning Lua

Experiment with syntax and control flow without installing an interpreter.

Quick algorithm checks

Validate a small loop, recurrence or string routine before moving it into a project.

Teaching

Demonstrate the effect of an instruction budget and of infinite loops safely.

Snippet scratchwork

Draft Lua helpers and copy the printed output for notes or tests.

Supported Lua subset

CategorySupported
ValuesNumbers, strings, booleans, nil and functions
Operators+ - * / % ^, .. concatenation, == ~= < > <= >=, and/or/not, # string length
Statementslocal, assignment, if/elseif/else, while, numeric for, function, return, break, calls
Builtinsprint, tostring, tonumber, type, math.*, string.*
Not supportedTables, io/os, require, metatables, coroutines, generic for-in pairs

Comments use Lua syntax: -- line comments and --[[ long comments ]].

Common mistakes

Mistake:Expecting a full Lua runtime with tables and modules.

Fix:This is a teaching subset implemented in TypeScript; io, os, require and tables are intentionally absent.

Mistake:Using a generic for loop with pairs/ipairs.

Fix:Use a numeric for loop (for i = 1, n do ... end) instead.

Mistake:Running an infinite loop with a very large budget.

Fix:Lower the budget when experimenting; the interpreter always stops eventually, but a huge budget means a long run.

Mistake:Assuming Lua 5.4 integer/float display fidelity.

Fix:Numbers are JavaScript numbers; integral values print without a decimal point.

Mistake:Expecting scripts to persist after reload.

Fix:The draft and result live in memory only; nothing is saved or uploaded.

Frequently asked questions

Is this a complete Lua 5.4 interpreter?

No. It is a teaching subset implemented in dependency-free TypeScript. It covers variables, expressions, conditionals, while and numeric for loops, functions with return, and a small set of builtins. Tables, metatables, coroutines, io, os and require are deliberately out of scope.

How does the instruction budget work?

Each statement, loop iteration and expression evaluation consumes one step. When the configured budget (100,000 by default in the UI) is exceeded, the run stops with an 'Execution budget exceeded' error and reports the steps used. This makes an accidental infinite loop harmless.

Which built-in functions can I call?

print, tostring, tonumber and type are global. The math namespace provides floor, ceil, abs, sqrt, max, min and pi; the string namespace provides len, upper, lower, rep and sub. Calls to unknown functions fail with a clear error.

Why does my script print nothing?

Only values passed to print are captured. Assignments and expressions are evaluated silently, and a return at top level ends the run without output. Check the Problems view for errors that may have stopped execution early.

Does the playground download a wasm runtime?

No. The interpreter is plain JavaScript/TypeScript bundled with the page, so there is no large engine download, no service worker and no network request while running scripts.

Are my scripts uploaded or saved?

Neither. Scripts and output stay in the browser tab. There is no persistence between runs or reloads, and nothing is transmitted anywhere.

References & standards