loadstring

Compiles Luau source without running it.

Syntax

Signature
loadstring(Source: string, ChunkName: string?) -> (function?, string?)

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
SourcestringLuau source to compile.
ChunkNamestring?Accepted for compatibility. It does not change the chunk name.

Returns

TypeDescription
function?Compiled function on success, or nil on failure.
string?Error message on failure. No second value is returned on success.

Notes

A compile or load failure returns nil and an error message. Loaded chunks use the name =loadstring. The optional ChunkName argument is currently ignored.

Example

Luau
local Function, Error = loadstring("return 6 * 7")
assert(Function, Error)
print(Function())