ToolBox.Online

Lua Beautifier - Free Online Lua Code Formatter

Beautify and format Lua code online for free. Auto-indent, clean up whitespace, and make your Lua scripts readable.

What is Lua Beautifier?

Lua is a lightweight, high-performance scripting language widely used in game development (Roblox, World of Warcraft, Love2D), embedded systems, web servers (Nginx/OpenResty), and as an extension language in applications like Neovim, Redis, and Adobe Lightroom. A Lua beautifier takes messy, compressed, or inconsistently formatted Lua code and restructures it with proper indentation, consistent spacing, and clear block nesting. This makes the code much easier to read, debug, and maintain. Lua's block structure uses keyword pairs like function/end, if/then/end, for/do/end, while/do/end, and repeat/until, which can become difficult to follow when not properly indented, especially in deeply nested game logic or configuration scripts.

How to Use Lua Beautifier

Paste your Lua code into the input field. Click "Beautify" to automatically format it with proper indentation for if/else, function, for, while, and repeat blocks. Nested blocks are indented consistently, making the code structure immediately visible. Copy the beautified code from the output area with one click.

How Lua Beautifier Works

The beautifier processes Lua code by recognizing block-opening and block-closing keywords: • Block openers: function, if...then, for...do, while...do, repeat, else, elseif • Block closers: end, until, else, elseif • Each block opener increases the indentation level by one step (2 spaces) • Each block closer decreases the indentation level before printing the closing keyword • Blank lines between functions are preserved for readability • String literals and comments are preserved exactly as written The beautifier handles all standard Lua constructs including nested blocks, multi-line strings, local function declarations, and method definitions with the colon syntax (obj:method()).

Common Use Cases

  • Formatting Roblox Lua scripts for readability and collaboration
  • Cleaning up minified or obfuscated Lua code for analysis
  • Beautifying Neovim configuration files (init.lua, plugin configs)
  • Making Lua game mods (World of Warcraft, Garry's Mod) readable for editing
  • Formatting OpenResty/Nginx Lua scripts for code reviews
  • Standardizing code style before committing Lua projects to version control

Frequently Asked Questions

What Lua constructs does this beautifier handle?

It handles all standard Lua constructs including functions, if/elseif/else blocks, for loops (both numeric and generic), while loops, repeat/until loops, and arbitrarily nested blocks with proper indentation.

Can I customize the indentation?

The default indentation is 2 spaces per level, which is the most common convention in Lua projects. This consistent style works well for most codebases including Roblox, Neovim, and game development.

Does it work with Roblox Luau?

Yes, the beautifier handles standard Lua syntax which is the foundation of Roblox Luau. Basic Luau features like type annotations are preserved, though advanced Luau-specific syntax may be treated as regular code.

Will it modify my string contents?

No. The beautifier only changes whitespace and indentation outside of string literals. All your string contents, including multi-line strings delimited by [[...]], are preserved exactly as written.

Can it format minified Lua code?

Yes. The beautifier can take single-line, minified Lua code and expand it into properly indented, readable format. This is useful for analyzing compressed scripts or game mods.

Does it handle comments?

Yes. Both single-line comments (--) and multi-line comments (--[[...]]) are preserved in their relative positions within the code.

Related Tools