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.
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.
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.
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.
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.
The console holds at most 20,000 characters of output, and the code is limited to 100,000 characters.
No. The script is run by Fengari inside a Web Worker in the page, and the code and its output stay in your browser.
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.