Macro FAQs
What is LuaWarden's macro system used for?
LuaWarden's macro system lets you selectively apply extra compiler passes inside your Luau script—binding bytecode decryption to runtime invariants, encrypting high-value constants with custom keys, rewriting sensitive integer math into mixed boolean-arithmetic (MBA), or placing hard tamper traps—so you can tune the exact balance between performance and security.
My script errors when I run it without obfuscation. What do I do?
Define passthrough shims at the top of your script inside an if not LW_OBFUSCATED then block. During compilation, LuaWarden strips the entire not LW_OBFUSCATED branch and replaces every macro call with its compiled VM transform.
Shim definitions must be declared as globals inside if not LW_OBFUSCATED then. Declaring them as local variables prevents the compiler from stripping them cleanly. Copy the ready-to-use Passthrough Shim SDK below.
Reserved LW_ identifier prefix
All identifiers beginning with LW_ are reserved for LuaWarden compiler directives and internal macros. Using an unknown macro (for example LW_UNKNOWN()) or declaring a user local with the prefix (local LW_CUSTOM = 1) raises a compile-time error to prevent silent typos in security-critical checks.
Which plans include macros?
All LuaWarden macros are available on every plan (Now, Basic, Premium, Commercial, and Enterprise) with no tier locks. For full build & loader setup, see the main documentation.
| Macro | Kind | Summary |
|---|---|---|
LW_PRECHECK | PRE-BOOT | Inlines a validation check whose return value decrypts the main VM bytecode. |
LW_ASSUME | CALLABLE | Binds an expected runtime value into VM key derivation and specialization. |
LW_OPAQUE | CALLABLE | Emits an opaque boolean predicate to defeat static CFG/dataflow recovery. |
LW_ENCSTR | CALLABLE | High-strength string constant encryption with optional runtime key binding. |
LW_ENCBUF | CALLABLE | Luau buffer-backed encrypted constant decryption with optional runtime key. |
LW_ENCNUM | CALLABLE | Type-preserving numeric encryption with optional multi-key runtime table. |
LW_REWRITE | CALLABLE | Rewrites integer/bitwise expressions into hardened MBA equivalents. |
LW_STACKALLOC | CALLABLE | Allocates fixed register-backed arrays on the VM stack without heap tables. |
LW_CRASH | TERMINAL | Corrupts VM context state and terminates execution immediately. |
LW_OBFUSCATED | VALUE | Compile-time true constant; dead branches are stripped completely. |
LW_LINE | VALUE | Compile-time constant folded to the source line number without debug info. |
Passthrough Shim SDK
Paste this block at the top of your script during local development. When running raw Luau it acts as a zero-logic passthrough; when compiled through LuaWarden the entire if not LW_OBFUSCATED then block is eliminated with zero traces left in the output.
if not LW_OBFUSCATED then
LW_ASSUME = function(expr, _expected) return expr end
LW_OPAQUE = function(b) return b end
LW_ENCSTR = function(s) return s end
LW_STRENC = LW_ENCSTR
LW_ENCBUF = function(s) return buffer.fromstring(s) end
LW_BUFENC = LW_ENCBUF
LW_ENCNUM = function(n) return n end
LW_NUMENC = LW_ENCNUM
LW_REWRITE = function(expr) return expr end
LW_PRECHECK = function(fn) fn() end
LW_CRASH = function() error("LW_CRASH", 0) end
LW_STACKALLOC = function(size)
local t = table.create(size)
return setmetatable(t, {
__index = {
pack = function(self, i, j)
return table.pack(table.unpack(self, i or 1, j or size))
end,
unpack = function(self, i, j)
return table.unpack(self, i or 1, j or size)
end,
clear = function(self, i, j)
for idx = i or 1, j or size do self[idx] = nil end
end,
},
})
end
LW_LINE = 0
endCallable Macros
Inlines check directly into LuaWarden's pre-boot loader and uses expectedKey ahead of time to encrypt the main script's VM bytecode. Decryption only succeeds at runtime if check() returns the exact expected integer or list of integers—letting you bind execution to custom whitelist endpoints, integrity checks, or environment validation.
- Multiple
LW_PRECHECKstatements can be defined and chained in the same script. checkmust be an anonymous zero-argument function with no upvalues other than_ENV.expectedKeymust be a compile-time integer literal (for example0x12345678) or a literal array of integers.- Must be written as a statement (produces no return value). Inside a precheck you may use nested functions and
LW_ENCSTR.
LW_PRECHECK(function()
return tonumber(game:HttpGet("https://auth.example.com/check"))
end, 0x12345678)
LW_PRECHECK(function()
return { compute_integrity_values() }
end, { 0x1234, 0x56789, -0x123456 })Tells LuaWarden that expression evaluates to expected (currently accepts numeric values). The compiler snapshots the expression at the macro site and folds it into internal VM decryption and handler specialization inside the enclosing function scope, making static recovery infeasible without knowing the true runtime value.
Because the expression is snapshotted at the macro call site, later writes to upvalues or locals referenced by expression do not affect the assumed key.
LW_ASSUME(game.PlaceId, 123456789) LW_ASSUME(someResult(), 0xABCDEF)
Generates an opaque boolean predicate that resolves to true or false at runtime while remaining non-trivial to static control-flow and data-flow analyzers. Pair with LW_ASSUME to derive predicates directly from runtime environment invariants.
if LW_OPAQUE(true) then
runProtectedLogic()
else
-- Unreachable dead branch
LW_CRASH()
endEncrypts a string constant with a dedicated high-strength cipher and lazy runtime materialization. When key and expression are supplied, the string is encrypted at compile time under key and decrypted at runtime using expression.
- Integer key: compile-time integer constant (smaller key space; prefer 256-bit hex keys for critical secrets).
- 64-char hex string: 256-bit key such as
"6c75...2331". "{...}"hex table-string: 64 hex characters in braces ("{6c75...2331}"), expectingexpressionto evaluate to a 32-byte array{ 0x6c, 0x75, ..., 0x31 }.
If the runtime expression does not match the compile-time key, decryption produces corrupted output or terminates execution.
local secret = LW_ENCSTR("Important String", 0xDEADBEEF, getRuntimeKey())
local myString = LW_ENCSTR("Important String")
print(LW_ENCSTR("Hello, World!"))
return LW_STRENC("Goodbye!")Encrypts a string constant with the same cipher and key-binding modes as LW_ENCSTR, returning a native Luau buffer instead of an interned string so sensitive bytes can be read and wiped with buffer.fill after use.
local secret = LW_ENCBUF("Important String", "{6c75...2331}", getRuntimeKey())
local myBuf = LW_ENCBUF("Important String")
print(buffer.tostring(LW_BUFENC("Hello, World!")))Encrypts a numeric constant (integers and IEEE-754 doubles, preserving exact value semantics). The optional keyTable binds decryption to up to 8 runtime expressions mapped to their expected compile-time integers: { [runtimeExpr] = expectedInt }.
local bound = LW_ENCNUM(1000, { [getSlot()] = 42 })
local myNumber = LW_ENCNUM(1000)
print(LW_ENCNUM(1), LW_NUMENC(1.0))
return LW_ENCNUM(1E100)Rewrites integer/word arithmetic (+, -, *, bitwise ops, shifts) into an algebraically equivalent Mixed Boolean-Arithmetic (MBA) expression while preserving Luau 32-bit word semantics.
- Captures up to 8 distinct locals, upvalues, or globals (localize table fields like
t.xbefore rewriting). preset:"fast","standard"(default),"strong", or"extreme"(case-insensitive; passing a string directly is shorthand for{ preset = "..." }).budget:"small","medium"(default), or"large"to bound expansion size.context: array of extra identifiers to fold into constant expressions (at least 2 required when rewriting a pure constant).
local left, right, offset = 5, 7, 3
local result = LW_REWRITE((left + right) - offset, {
preset = "strong",
budget = "medium",
})
local mixed = LW_REWRITE(bit32.bxor(bit32.lshift(left, 3), right), "fast")
-- Constant rewriting with context identifiers:
local salt, state = 73, 29
local constant = LW_REWRITE(12345, { preset = "fast", context = { salt, state } })Allocates size consecutive registers directly on the VM stack without creating a heap table object. Pass 1 (default) for 1-indexed arrays or 0 for 0-indexed arrays. Must be bound to a non-escaping local variable.
- Supports constant indexing (
t[1]), dynamic indexing (t[f()]), and compile-time folded length (#t). - Supports inlined proxy operations:
t:pack(i, j),t:unpack(i, j), andt:clear(i, j)(range defaults to full array). - May be captured as an upvalue across closures and inlined call sites.
local values = LW_STACKALLOC(64) values[1] = 1 values[64] = 64 values[x()] = 0 assert(#values == 64) return values:pack()
Securely corrupts internal VM state, wipes active key buffers, and terminates execution immediately regardless of passed arguments or surrounding pcall traps.
if tamperDetected() then
LW_CRASH()
endValue Macros
Compile-time boolean constant folded to true during obfuscation. Conditional branches gated on LW_OBFUSCATED are evaluated at compile time and unreachable branches are stripped completely with zero traces in the output.
Branch blocks still keep their lexical scope—declare locals in the parent scope before assigning inside if LW_OBFUSCATED then. Do not call LW_OBFUSCATED() as a function.
if LW_OBFUSCATED then
validateWhitelist()
else
-- Stripped completely at compile time
skipWhitelist()
end
return LW_OBFUSCATED and runProduction() or runDebug()do
validateWhitelist()
end
return runProduction()Compile-time numeric constant replaced with the current source line number during compilation. Works even with all debug/line info stripped from the VM build.
local firstLine = LW_LINE -- folds to 1
print("Current line:", LW_LINE) -- folds to 2
error("Failed at #" .. LW_LINE) -- folds to 3