---
title: "Luraph Macros"
icon : "code"
description: "Compile-time directives Luraph reads when it obfuscates your script."
---

# Luraph Macros

Every script you upload is obfuscated with Luraph before EnvyAuth delivers it. Luraph reads identifiers that begin with `LPH_` and acts on them at obfuscation time. They don't appear in the delivered output — they're instructions to the obfuscator, not runtime functions.

EnvyAuth runs Luraph for you (Luau target, configured for executors), so there's nothing to set up.

<Warning title="Macros take constants, not variables">
  Most `LPH_` macros take a constant: a function, string, or number written inline at the call site, not a variable that holds one. If you pass a variable, Luraph rejects the build with a message like *"LPH_NO_VIRTUALIZE only accepts a single constant function as an argument."*
</Warning>

## Testing locally

The `LPH_` names don't exist in your raw source, so running the un-obfuscated script throws `attempt to call a nil value`. Luraph publishes an open-source [macro SDK](https://github.com/Luraph/macrosdk) that defines no-op versions of every macro so the script runs while you develop. Luraph ignores the shim on the real build.

A minimal stand-in for a single macro:

```lua
-- - dev-only: lets the raw script run before obfuscation. - \\
if not LPH_OBFUSCATED then
    function LPH_NO_VIRTUALIZE(f) return f end
end
```

---

## LPH_NO_VIRTUALIZE

Luraph is a VM-based obfuscator: it turns your code into instructions for its own interpreter. That's strong protection, but each operation costs many interpreter cycles, so code that runs many times per second becomes expensive. `LPH_NO_VIRTUALIZE` excludes a function from virtualization and compiles it to ordinary Lua instead. The result is faster but far less protected.

Takes **one constant function** and returns a function.

Use it for:

- `RenderStepped` / `Heartbeat` / `Stepped` connections
- `__index` and `__namecall` metamethod hooks
- tight `while` loops with no `wait`
- garbage-collector scan loops (`getgc`)
- any function called by one of the above

```lua
-- per-frame connection
RunService.RenderStepped:Connect(LPH_NO_VIRTUALIZE(function(dt)
    -- runs every frame; keep it out of the VM
end))

-- metamethod hook
local old
old = hookmetamethod(game, "__index", LPH_NO_VIRTUALIZE(function(t, k)
    return old(t, k)
end))

-- assign first, then connect
local generate_tracers = LPH_NO_VIRTUALIZE(function(a, b)
    -- ...
end)
heartbeat:Connect(generate_tracers)

-- immediately invoked; the trailing () actually runs it
LPH_NO_VIRTUALIZE(function()
    for _, v in pairs(getgc()) do
        -- ...
    end
end)()
```

Wrong usage:

```lua
-- Wrong: the argument is a variable, not a constant function
local function do_something() end
LPH_NO_VIRTUALIZE(do_something)

-- Wrong: not a single function expression
LPH_NO_VIRTUALIZE(
    local old; old = hookmetamethod(game, "__namecall", function(...) end)
)

-- Wrong: defined but never invoked — the body never runs (missing the trailing call)
LPH_NO_VIRTUALIZE(function()
    -- ...
end)
```

<Warning title="Don't wrap your whole script">
  Wrapping your whole script in `LPH_NO_VIRTUALIZE` ships your logic almost in the clear. Use it only on functions that run roughly 30 or more times a second.
</Warning>

---

## LPH_JIT and LPH_JIT_MAX

A middle ground between full virtualization and `LPH_NO_VIRTUALIZE`. Luraph applies a JIT-style transform that is faster than the VM but more protected than leaving the function un-virtualized. `LPH_JIT_MAX` optimizes more aggressively, which is faster but produces larger output.

Each takes **one constant function** and returns it.

```lua
local step = LPH_JIT(function(x) return x * x + 1 end)

local heavy = LPH_JIT_MAX(function(grid)
    -- math-heavy inner loop
end)
```

Wrong usage:

```lua
-- Wrong: variable, not a constant function
local f = function(x) return x end
local step = LPH_JIT(f)   -- "LPH_JIT only accepts a single constant function as an argument."
```

---

## LPH_NO_UPVALUES

Compiles a function so it captures no upvalues (no access to locals from the enclosing scope). Takes **one constant function** and returns it.

<Info title="Environment requirement">
  `LPH_NO_UPVALUES` requires `getfenv` and `setfenv`. Roblox / Luau executors provide them.
</Info>

```lua
local pure = LPH_NO_UPVALUES(function(a, b)
    return a + b          -- uses only its own arguments and globals
end)
```

Wrong usage:

```lua
-- Wrong: variable, not a constant function
local fn = function() end
LPH_NO_UPVALUES(fn)

-- Wrong (logic): the body relies on an upvalue, which won't be captured
local secret = 42
local f = LPH_NO_UPVALUES(function() return secret end)   -- `secret` is gone
```

---

## LPH_ENCSTR

Encrypts a **constant string** at obfuscation time and decrypts it at runtime only when it's read. Keeps webhook URLs, keys, and other sensitive literals out of a plain string dump. Alias: `LPH_STRENC`.

```lua
local webhook = LPH_ENCSTR("https://example.com/api/notify")
```

Wrong usage:

```lua
-- Wrong: a variable is not a constant string
local url = "https://example.com/api/notify"
local webhook = LPH_ENCSTR(url)        -- "LPH_ENCSTR only accepts a single constant string as an argument."

-- Wrong: concatenation is not a single constant
local webhook = LPH_ENCSTR("https://" .. host .. "/notify")
```

---

## LPH_ENCNUM

The number counterpart to `LPH_ENCSTR` — encrypts a **single constant** double or integer. Alias: `LPH_NUMENC`.

```lua
local place_id = LPH_ENCNUM(1818)
local mask     = LPH_ENCNUM(0xDEADBEEF)
```

Wrong usage:

```lua
-- Wrong: variable, not a constant number
local n = 1337
local key = LPH_ENCNUM(n)              -- "LPH_ENCNUM only accepts a single constant double or integer as an argument."
```

---

## LPH_ENCFUNC

Encrypts a whole function. It's decrypted lazily the first time it runs, and only if the decryption key matches. Most scripts won't need this. Alias: `LPH_FUNCENC`.

Takes three arguments: a **constant function**, a **constant string** encryption key, and a **string variable** decryption key (resolved at runtime).

```lua
local dec_key = get_runtime_key()      -- a string variable, resolved at runtime
local protected = LPH_ENCFUNC(
    function()
        -- only decrypted + run when dec_key matches the encryption key
    end,
    "my-constant-enc-key",             -- constant string
    dec_key                            -- string variable
)
```

Wrong usage:

```lua
-- Wrong: the function must be a constant, and the enc key must be a constant string
local f = function() end
LPH_ENCFUNC(f, some_key, dec_key)      -- "LPH_ENCFUNC accepts a constant function, constant string, and string variable as arguments."
```

---

## LPH_OBFUSCATED

A boolean that Luraph replaces with `true` during obfuscation. In your raw source it's `nil`. Use it to refuse to run when the script wasn't processed, or to gate dev-only code.

```lua
-- bail out if someone runs the unprotected source
if not LPH_OBFUSCATED then
    return
end
```

```lua
-- dev-only helpers that vanish in the real build
if not LPH_OBFUSCATED then
    print("debug build")
end
```

<Info title="It's a value, not a call">
  `LPH_OBFUSCATED` is a boolean. Don't call it — `LPH_OBFUSCATED()` is wrong.
</Info>

---

## LPH_CRASH

Crashes and corrupts the VM context with no clean recovery. Call it from your own integrity checks when you detect tampering. Takes **no arguments**.

```lua
if detected_hook or being_debugged then
    LPH_CRASH()
end
```

Wrong usage:

```lua
-- Wrong: it takes no arguments
LPH_CRASH("tampering detected")        -- "LPH_CRASH does not accept any arguments."
```

---

## See also

- [EnvyAuth Macros](/docs/macros/luaegis) — the `LGS_*` globals the loader injects at runtime (user identity, key info, secure requests).
