Lua Formatter
Paste code in both editors to see differences
Hint: Paste original code on left, modified code on right, then click Compare to see differences highlighted.
Hint: Paste your code, customize font size and line numbers, then click Export PDF to download formatted code.
Hint: Paste your JWT token to decode and view its header, payload, and signature. The tool validates token structure and format.
Hint: Select conversion type, paste your data, and get instant conversion. Supports JSON, YAML, XML, Excel, PDF, and more.
Issue Description
Hint: Paste any code and click Format to beautify indentation, spacing, and structure instantly.
How It Works
- Step 1: Paste unformatted Lua code including functions, tables, control structures, and metatables with inconsistent indentation or spacing.
- Step 2: The formatter parses Lua syntax identifying keywords (local, function, if, for, while), operators, table constructors, and comment blocks (-- single line, --[[ multi-line ]]).
- Step 3: Applies Lua style conventions with 2-space indentation, consistent spacing around operators (=, +, ..), and proper line breaks after function/table definitions.
- 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
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 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.