2025-05-04 18:08:25 -05:00

35 lines
1.1 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. There are no restrictions on the length or the allowed characters of the keys, only that they are the same.
## Valid Usage
```lua
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!" /%}}