Lua Playground

Run Lua in the browser.

The Lua Playground runs a Lua 5.3 script in your browser and shows what print() and io.write() produce in a console pane. A runtime error is reported with its line number, and the program is stopped if it runs for more than 5 seconds.

What is Lua and how does this playground run it?

Lua is a small, fast scripting language that is designed to be embedded in other programs. It is widely used for game scripting, configuration and extensions in tools such as Nginx and Redis. The language has few concepts: nil, booleans, numbers, strings, functions, tables and coroutines. A table is the only data structure and works as an array, a dictionary or an object, and by convention arrays start at index 1. Variables are global unless declared local. This playground uses Fengari, a Lua VM written in JavaScript that follows Lua 5.3, so integers and floats are distinct subtypes, // is floor division and the utf8 library exists. The script runs in a separate Web Worker with a restricted environment: file, process, module and debug access is removed, and print and io.write are replaced by functions that send text to the console pane.

How to use Lua Playground

  1. Write or load a script Type Lua code into the Lua code editor, or pick a program from the Sample program menu. Code longer than 100,000 characters is rejected.
  2. Press Run Click Run. The script executes in a worker and the Console pane fills with the output while it runs.
  3. Read the console Output from print() and io.write() appears in the Console. Use the copy button above it to copy the text.
  4. Fix errors If the script fails, a message such as 'Line 3: attempt to index a nil value (local 't')' appears below the panes and the editor highlights the line. Edit the code and run again.
  5. Stop long runs Click Stop to end a script manually, or wait for the 5 second limit. Use Clear to empty the editor.

Frequently asked questions

Which Lua version is this?

Lua 5.3, provided by Fengari. Printing _VERSION shows Lua 5.3. LuaJIT and Lua 5.1 differ in several ways, for example they do not have integer division or separate integer and float numbers.

Which functions are removed?

The globals dofile, loadfile, require, package, io, debug and collectgarbage are removed, and the os functions execute, exit, remove, rename, getenv, tmpname and setlocale are removed. The io table is replaced by one that only has io.write. The coroutine, table, string, utf8, math and os libraries are otherwise available, and so are functions such as os.time and os.clock.

How long can a script run?

5 seconds. After that the worker is terminated and the message 'Execution stopped: the program ran longer than 5 seconds (possible infinite loop).' is shown. You can also stop it earlier with the Stop button.

Is there a limit on output or code size?

The console holds at most 20,000 characters of output, and the code is limited to 100,000 characters.

Is my code sent anywhere?

No. The script is run by Fengari inside a Web Worker in the page, and the code and its output stay in your browser.

Why do I see 5.0 instead of 5?

In Lua 5.3 the / operator always produces a float, and floats are printed with a decimal point. Use // for floor division, which keeps integers as integers.