Lua Formatter

Code Formatter
Tools
INPUT
0 chars • 1 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
OUTPUT
0 chars • 1 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Hint: Paste any code and click Format to beautify indentation, spacing, and structure instantly.

We never store your code

How It Works

  1. Step 1: Paste unformatted Lua code including functions, tables, control structures, and metatables with inconsistent indentation or spacing.
  2. Step 2: The formatter parses Lua syntax identifying keywords (local, function, if, for, while), operators, table constructors, and comment blocks (-- single line, --[[ multi-line ]]).
  3. Step 3: Applies Lua style conventions with 2-space indentation, consistent spacing around operators (=, +, ..), and proper line breaks after function/table definitions.
  4. Step 4: Outputs formatted code following Lua community standards, improving readability for game scripting (Roblox, Love2D), embedded systems, and configuration files.

Lua Formatting Examples

Example: Lua Function and Table Formatting

Unformatted Lua Input
function calculate(x,y)local result=x+y;return result end
local player={name="Hero",health=100,inventory={"sword","shield"},attack=function(self,target)target.health=target.health-10 end}
if player.health>0 then print("Alive")else print("Dead")end
Formatted Lua Output
function calculate(x, y)
  local result = x + y
  return result
end

local player = {
  name = "Hero",
  health = 100,
  inventory = { "sword", "shield" },
  attack = function(self, target)
    target.health = target.health - 10
  end
}

if player.health > 0 then
  print("Alive")
else
  print("Dead")
end

Key Changes:

The formatter transforms compressed Lua into readable code following Lua style guidelines. Function parameters (x, y) gain spacing after commas for clarity. The 'local' keyword is properly positioned at line start, following Lua's scoping best practices. Table constructors are reformatted with consistent key-value spacing (name = 'Hero') and proper indentation for nested structures like the inventory array and attack method. The semicolon after 'x+y' is removed as Lua doesn't require statement terminators. Operators (=, +, >) receive surrounding spaces per Lua conventions. The if-then-else block expands from single-line to multi-line format with 2-space indentation, matching standards used in Roblox Studio, Love2D game development, and Neovim configuration files. This formatting improves debugging, code reviews, and collaboration in Lua projects where readability directly impacts development speed.

Frequently Asked Questions

What is a Lua formatter?

A Lua formatter is a tool that formats Lua code according to Lua style style guidelines. It automatically applies proper indentation, spacing, line breaks, and formatting rules to make Lua code more readable and maintainable.

Does the Lua formatter follow Lua style?

Yes, our Lua formatter follows Lua style style guidelines, including proper indentation (4 spaces), line length limits, spacing around operators, and other Lua formatting best practices.

Is the Lua formatter free?

Yes, our Lua formatter is completely free to use with no limits. There's no registration required, and all processing happens in your browser for maximum privacy.

Can I format Lua 3 code?

Yes, our Lua formatter supports both Lua 2 and Lua 3 syntax. It formats code while preserving Lua version compatibility.

Does the formatter fix syntax errors?

The formatter will format valid Lua code. If there are syntax errors, it will attempt to format what it can, but you should fix syntax errors first for best results.

What Lua features are supported?

Our Lua formatter supports all Lua features including classes, functions, decorators, list comprehensions, f-strings, type hints, and all standard Lua syntax.