Lua Minifier
Paste a Lua script and produce compact Lua that keeps strings, long brackets, shebangs and token boundaries intact. Strip comments and whitespace, preserve license banners by default, keep line structure when you need readable errors, and opt into scope-aware local renaming when size matters.
About this tool
Lua is flexible about whitespace, which makes it a good fit for minification: comments, blank lines and indentation can usually disappear without changing how the chunk runs. This tool scans Lua as Lua tokens instead of doing a blind regular-expression replace, so quoted strings, long strings, long-bracket levels, shebangs and tricky token boundaries survive.
Use it when you need a smaller plugin, game script, embedded config chunk or LuaJIT helper. The default output strips comments and joins the script onto one line. Turn on local renaming when you want a smaller payload and the script does not inspect its own local names with debug APIs.
Worked example
Input:
--! @license MIT
local function greet(name)
-- build a greeting
local message = "hello, " .. name
print(message)
end
greet("Ada")
With Strip Lua comments and Preserve license / copyright banners enabled, the output keeps the banner and removes the internal comment and spacing:
--! @license MIT
local function greet(name)local message="hello, "..name print(message)end greet("Ada")
If Rename locals and parameters to short aliases is enabled, local variables and parameters are shortened while globals, fields, method names and string contents are left alone.
Limits and edge cases
- The transform is token-aware, not a full Lua AST optimizer. It does not fold constants, reorder code, remove dead branches or encode strings.
- Local renaming is opt-in and refuses when block structure does not balance. Minification without renaming is still forgiving for incomplete snippets.
--!,@license,@preserveand@copyrightcomments are kept by default; disable the banner option to strip them too.line_breaks = keepkeeps one output line per non-empty source line, useful when runtime error line numbers matter more than the smallest possible result.- Code that reflects over local names with
debug.getlocal, builds code strings that mention local names, or depends on exact source text should not use local renaming.
FAQ
Is this an obfuscator?
No. It is a size-reducing minifier. It removes comments and unnecessary whitespace, and it can rename locals to shorter names, but it does not encode strings, insert control-flow traps or try to hide what the code does. The output is still Lua source intended to run the same way as the input.
What names are safe to rename?
Only locals, local function names and function parameters are candidates. Globals, table fields,
method names, table-constructor keys, goto labels and anything inside a string are never renamed.
Aliases are unique across the file and avoid global names already used by the script.
Why preserve license comments by default?
Minification often runs right before publishing a file, and it is easy to strip required attribution
accidentally. The default keeps comments marked with --!, @license, @preserve or @copyright.
If you own the file and want the smallest possible output, turn that option off.
Will it change strings or long brackets?
No. Short strings, long strings and long-bracket contents are emitted exactly as scanned. A comment
marker such as -- inside a string remains part of the string, and nested long-bracket levels such
as [=[ ... ]=] keep their original delimiters and contents.
Developer & Automation Access
Run it from the terminal
Same engine as this page, headless — via the gizza CLI:
gizza tool lua-minifier '--! @license MIT
local function greet(name)
-- build a greeting
local message = "hello, " .. name
print(message)
end
greet("Ada")'New to the CLI? Get gizza →
Open it by URL
Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:
https://gizza.ai/tools/lua-minifier/?code=--%21%20%40license%20MIT%0Alocal%20function%20greet%28name%29%0A%20%20--%20build%20a%20greeting%0A%20%20local%20message%20%3D%20%22hello%2C%20%22%20..%20name%0A%20%20print%28message%29%0Aend%0A%0Agreet%28%22Ada%22%29&remove_comments=true&keep_license=true&rename_locals=true&line_breaks=stripMachine-readable descriptor: tool.json — title + parameters JSON Schema for agents.
