Lua Formatter
Beautify and re-indent Lua code instantly.
About the Lua Formatter
What is a Lua formatter?
Lua does not care about whitespace. You can write an entire program on one line and it runs exactly the same, which is why Lua that has been minified, generated by a tool, or pasted out of a config file so often arrives as an unreadable wall of text. A Lua formatter rebuilds that code with consistent indentation and one statement per line, so you can actually read it.
This one works on the token stream rather than by matching patterns in the text. It reads your code the way Lua itself does, which means long strings such as [==[ ... ]==], long comments, escaped quotes, and hex floats like 0xA23p-4 are understood as single units and never mangled. Blocks opened by do, then, function, and repeat are indented and closed at the right depth, and tables are expanded onto multiple lines only when they are long enough to need it.
How to Use This Tool
- Paste your Lua. Type or paste it into the left pane, or use Open file to load a
.luafile. It formats as you type. - Pick your indent. Two spaces, four spaces, or a tab. Four is the Lua reference manual's own style.
- Check the badge. A green badge means the code parsed cleanly. A red one names the problem and the line it is on.
- Take the output. Copy it, download it as a
.luafile, or send it to the Lua Minifier with the button underneath.
Common Use Cases
- Reading minified or obfuscated Lua: Turn a single-line script back into something you can follow.
- Cleaning up game and mod scripts: Roblox, Garry's Mod, World of Warcraft addons, and Love2D projects all end up with inconsistent indentation over time.
- Reviewing a diff: Format both sides first and the real changes stop hiding behind whitespace noise.
- Standardising a config file: Lua is a common config format, and a consistent layout makes tables far easier to scan.
- Learning Lua: Seeing your own code correctly indented makes block structure obvious.
Need to go the other way? The Lua Minifier strips this back down for shipping. You may also want the JSON Formatter or the SQL Formatter, or the rest of our free developer tools.
Frequently Asked Questions
Which versions of Lua does this support?
The tokenizer covers Lua 5.1 through 5.4, including integer division with //, the bitwise operators added in 5.3, goto labels, and hexadecimal floats. Code written for LuaJIT works too, since it shares the 5.1 syntax.
Does it work with Roblox Luau?
Ordinary Roblox scripts format normally, because Luau is built on Lua 5.1 syntax. Luau's optional type annotations are a different matter. They are read without error and every token is preserved, but they are not laid out the way you would write them by hand, since type syntax is not part of standard Lua. If your scripts are heavily typed, expect to tidy those lines yourself.
Can formatting change what my code does?
It should not. The formatter only adds and removes whitespace between tokens, and every token you put in comes out in the same order. Strings and comments are copied through untouched. That said, always keep the original until you have run the formatted version.
Why did my table stay on one line?
Short tables read better inline, so a table is only expanded onto separate lines when it would otherwise run past roughly 78 characters, or when it contains a function. That keeps {1, 2, 3} compact while a long configuration table gets one entry per line.
What does the red badge mean?
It means the code could not be read as valid Lua, and it names the reason and line, for example an unterminated string or an unclosed block. The output is left empty rather than showing you a guess based on code that does not parse.
Are my scripts uploaded anywhere?
No. The tokenizer and formatter are plain JavaScript running in your browser, so your code never leaves the machine and the tool keeps working offline once the page has loaded.