loadstring
Compiles Luau source in the executor environment and returns a function.
Syntax
loadstring(source: string, chunkname?: string) -> function
Parameters
| Parameter | Type | Description |
|---|---|---|
source | string | Luau source code to compile or execute. |
chunkname? | string | The chunkname value used by the call. |
Returns
| Type | Description |
|---|---|
function | A function |
Description
loadstring is part of the Closures library. Closure helpers operate on live Luau function objects. Hooks redirect future calls through the replacement closure and return the previous implementation.
Each call creates or returns a fresh object or value that you can store and pass to other functions.
Example
local fn = loadstring("return 21 * 2", "double")
print(fn())
Notes
- Closure operations act on live Luau function objects; installed hooks remain active until restored.