loadstring
Compiles a string of Luau source into a callable chunk. Returns nil plus an error message when the source fails to compile.
Signature
loadstring(source: string, chunkName: string?): ((...any) -> ...any)? , string?Parameters
sourcestringThe Luau source to compile.
chunkNamestring?Optional name shown in tracebacks.
Returns
function?, string?
Example
local chunk, err = loadstring("return 1 + 1")
if not chunk then
warn(err)
return
end
print(chunk())