MoonVeil-Docs/content/docs/macros/MV_ENC_FUNC.md
2025-05-02 02:25:57 -05:00

36 lines
1.0 KiB
Markdown

---
weight: 100
title: "MV_ENC_FUNC"
description: "Encrypts functions"
icon: "article"
date: "2025-05-01T18:47:58-05:00"
lastmod: "2025-05-01T18:47:58-05:00"
---
`declare function MV_ENC_FUNC<A..., R...>(vmFunction: (A...) -> R..., encryptKey: string, decryptKey: string): (A...) -> R...`
will virtualize and encrypt the passed function constant with the provided `encryptKey`. Then `decryptKey` is evaluated at runtime to grab the key.
## Valid Usage
```lua
local foo = 'ok'
local total = 0
local getKey = MV_VM(function()
-- WARNING: this is just an example! don't do this
return "pass" .. "word123"
end)
for i = 1, 10 do
-- referenced upvalues will be captured
MV_ENC_FUNC(function()
print("in virtualized function # 1", i)
total = total + i
end, "password123", getKey())()
end
return total
```
{{% alert context="warning" text="**Note**: if your plan doesn't include virtualization support, `MV_ENC_FUNC` is a no-op where the passed function is mangled normally and not virtualized or encrypted!" /%}}