Skip to content
File systemOverview

loadfile

Local script-loading API.

Details#

Reads a workspace-relative script file and compiles it without executing the chunk. Check the returned function before calling it. Missing files and compilation failures differ from errors raised by the chunk itself.

Examples#

Example

Luau
local path = "docs-load-example.luau"
assert(not isfile(path), "Example file already exists")
writefile(path, "return 42")
local chunk, err = loadfile(path)
if chunk then print(chunk()) else warn(err) end
delfile(path)