smelt.fs¶
Tier: Host — Available in every runtime, including headless mode.
Sync filesystem primitives. Errors use the (value, err_string) convention so callers can distinguish failures without pcall.
smelt.fs.copy¶
Copy file from to to. Returns (bytes_copied, nil) on success or (nil, err_string) on failure.
smelt.fs.exists¶
Return true if a filesystem entry exists at p.
smelt.fs.glob¶
Find paths matching pattern under path (defaults to cwd). Returns the matches sorted newest-first, capped at opts.max (default 200). On error returns (nil, err_string).
smelt.fs.is_dir¶
Return true if p exists and refers to a directory.
smelt.fs.is_file¶
Return true if p exists and refers to a regular file.
smelt.fs.mkdir¶
Create directory p (parents must exist). Returns (true, nil) on success or (false, err_string) on failure.
smelt.fs.mkdir_all¶
Create directory p along with any missing parent directories. Returns (true, nil) on success or (false, err_string) on failure.
smelt.fs.read¶
Read p into a string. Returns (content, nil) on success or (nil, err_string) on failure.
smelt.fs.read_async¶
Read path off the main thread. Must be called from inside
smelt.spawn(fn) or a tool.execute (anything that runs on the Lua
task runtime). Returns (content, nil) on success or (nil, err) on
failure — same convention as smelt.fs.read.
smelt.fs.read_dir¶
List the immediate entries of directory p. Returns (entries, nil) on success or (nil, err_string) on failure.
smelt.fs.remove_dir¶
Delete the empty directory at p. Returns (true, nil) on success or (false, err_string) on failure.
smelt.fs.remove_dir_all¶
Recursively delete the directory tree rooted at p. Returns (true, nil) on success or (false, err_string) on failure.
smelt.fs.remove_file¶
Delete the file at p. Returns (true, nil) on success or (false, err_string) on failure.
smelt.fs.rename¶
Rename or move from to to. Returns (true, nil) on success or (false, err_string) on failure.
smelt.fs.size¶
Return the size of file p in bytes. Returns (size, nil) or (nil, err_string) on failure.
smelt.fs.watch¶
fun(path: string, handler: fun(event: { kind: string, detail: string?, paths: string[] }), opts: table?): smelt.Reg
Types: smelt.Reg
Filesystem watcher. Calls handler(event) for each event, where
event = { kind, detail?, paths }. kind is one of "create" | "modify" | "remove" | "rename" | "access" | "other" | "any";
detail carries notify's sub-kind when one is reported (e.g. kind = "create" → detail = "file" | "folder").
opts.recursive defaults to true; set false to watch only the immediate
entries of a directory. Returns a Reg whose :remove() stops the
watcher and cancels the polling coroutine.
smelt.fs.write¶
Write contents to file p, creating it if necessary. Returns (true, nil) on success or (false, err_string) on failure.
smelt.fs.write_async¶
Write contents to path off the main thread. Same yielding rules as
smelt.fs.read_async. Returns (true, nil) on success or
(false, err) on failure — mirrors smelt.fs.write.