Loading…

Online Lua Compiler and Playground

Browser-based compiler and playground for Lua, Progsity IDE.

About Lua

Lua is a small scripting language built to be embedded: it scripts Roblox games, World of Warcraft add-ons, the Neovim editor and many network devices. The whole language fits in a short manual, with one data structure, the table, doing the work of arrays, maps and objects.

The playground runs the reference Lua interpreter in a sandbox. Integers are 64 bits and separate from floats, strings have their own pattern matching, and functions are values you can pass around and return.

Because the language is so small, it is a good place to learn closures, coroutines and metatables without a framework in the way.

How to use

  1. Write Lua at the top level of the file; there is no main function. Declare variables with local.
  2. Read input from the stdin panel with io.read: "l" for a line, "n" for a number.
  3. Press Run. A syntax error is reported with its line before anything runs.

FAQ

Which Lua is this?›

Lua 5.4, the reference interpreter from PUC-Rio. It is not LuaJIT, so 5.4 features such as integer division with // and the <const> attribute work.

Do arrays start at 1?›

By convention, yes. The length operator # and the standard library functions count from 1.

Can I require modules?›

The standard libraries (string, table, math, io, os, coroutine, utf8) are loaded already. LuaRocks packages are not installed, and a program is one file.

Why did 10 / 2 print 5.0?›

In Lua 5.4 the / operator always gives a float. Use // when you want an integer result.

Is running Lua here free?›

Yes, and it needs no account. Signing in adds saved snippets and share links.

Code examples

Tap “Try this” to load sample code into the editor above.

  • Sort a table

    local nums = {3, 1, 4, 1, 5, 9}
    table.sort(nums)
    print(table.concat(nums, " "))
  • Read two numbers

    local a, b = io.read("n", "n")
    print(a + b)
  • A counter made with a closure

    local function counter()
      local n = 0
      return function()
        n = n + 1
        return n
      end
    end
    
    local tick = counter()
    print(tick(), tick(), tick())
  • Words with string patterns

    for word in ("to be or not to be"):gmatch("%a+") do
      io.write(word:upper(), " ")
    end
    print()