loadstring
Compiles Luau source without running it.
Syntax
Signature
loadstring(Source: string, ChunkName: string?) -> (function?, string?)Aliases
This function has no aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
Source | string | Luau source to compile. |
ChunkName | string? | Accepted for compatibility. It does not change the chunk name. |
Returns
| Type | Description |
|---|---|
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())