writefile Synchronous
writefileasync
Save a string to a workspace file. A new file is created when necessary; writing an existing file replaces all of its previous contents. Use it to save a complete settings document or export. Serialize tables first, since this function stores bytes rather than Luau values.
Luau
writefile(path: string, contents: string) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path inside the Kawaii workspace, for example settings/theme.json. |
contents | string | String containing the bytes to write. Text and binary strings are accepted. |
Returns
()This function returns no values.
Usage notes
Missing parent folders are created automatically. To add to existing contents instead of replacing them, use appendfile.
Tables must be serialized before writing. For settings, encode the table with json.encode and decode it after reading.
Differences from Volt
Volt documents access through explicitly created workspace symlinks. Kawaii rejects symlinks in workspace paths; all workspace operations remain subject to its path containment checks.
Example
Luau
local settings = { theme = "dark", volume = 0.5 }
writefile("settings/preferences.json", json.encode(settings))
local saved = json.decode(readfile("settings/preferences.json"))
print(saved.theme) -- dark