Yuari
Documentation
Docs/File system/loadfile

loadfile(path) / dofile(path) / loadfileasync(path) / dofileasync(path) / load_file / loadfromfile / load_from_file / do_file

Loads or runs a Lua file from the workspace; dofile forwards the chunk's return values and async variants yield instead of blocking.

Syntax

loadfile(path: string) -> function | nil, string
dofile(path: string) -> ...any

Parameters

ParameterTypeDescription
pathstringWorkspace-relative path.

Returns

TypeDescription
function | ...anyloadfile returns the chunk; dofile returns everything the chunk returned.

Description

Logic change: dofile now calls the chunk with LUA_MULTRET and returns all of its values instead of discarding them, and errors raised inside the file reach the caller unchanged.

Logic change: loadfileasync and dofileasync are real async wrappers implemented on top of task.defer. The sync operation runs in a deferred task while the calling thread yields, then resumes with the results. They no longer block like the sync versions.

The file table (file.load, file.dofile, ...) keeps the same behavior.

Example

writefile("value.lua", "return 42")
print(dofile("value.lua")) -- 42
print(loadfileasync("value.lua")()) -- 42

Notes

  • loadfile returns nil, error on failure.