Yuari
Documentation
Docs/Closures/loadstring

loadstring

Compiles Luau source in the executor environment and returns a function.

Syntax

loadstring(source: string, chunkname?: string) -> function

Parameters

ParameterTypeDescription
sourcestringLuau source code to compile or execute.
chunkname?stringThe chunkname value used by the call.

Returns

TypeDescription
functionA 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.