Skip to content
Saiko

loadstring

Compiles a string of Luau source into a callable chunk. Returns nil plus an error message when the source fails to compile.

Signature

luau
loadstring(source: string, chunkName: string?): ((...any) -> ...any)? , string?

Parameters

sourcestring

The Luau source to compile.

chunkNamestring?

Optional name shown in tracebacks.

Returns

function?, string?

Example

luau
local chunk, err = loadstring("return 1 + 1")
if not chunk then
    warn(err)
    return
end
print(chunk())