Skip to content
Saiko

loadfile

Compiles a workspace file into a callable chunk, returning nil plus an error message on failure.

Signature

luau
loadfile(path: string, chunkName: string?): ((...any) -> ...any)?, string?

Parameters

pathstring

Path to the Luau file.

chunkNamestring?

Optional name shown in tracebacks.

Returns

function?, string?

Example

luau
writefile("hello.lua", 'print("loaded from a file")')

local chunk, err = loadfile("hello.lua")
if chunk then
    chunk()
else
    warn(err)
end