RbxStu V3 Docs
  • Welcome
  • Information
    • Engine Information
      • Luau API Security
  • Stunc
    • Overview
    • Connections
    • Filesystem
      • readfile
      • writefile
      • appendfile
      • isfile
      • isfolder
      • listfiles
      • makefolder
      • delfile
      • delfolder
      • loadfile
      • dofile
  • Memory
    • getgc
    • reference_object
    • unreference_object
    • get_gc_threshold
  • Closures
    • isunhookable
    • makeunhookable
    • ishooked
    • restorefunction
    • hookfunction
    • hookmetamethod
    • isourclosure
    • iscclosure
    • islclosure
    • clonefunction
    • newcclosure
    • newlclosure
    • loadstring
Powered by GitBook
On this page
  1. Stunc
  2. Filesystem

writefile

Overview of the writefile function.

Function definition
function writefile(path: string, content: string): ()

Errors:

  • Illegal Path

    • The path provided is considered 'unsafe'.

    • The extension is considered unsafe.

  • Failed to open file handle

    • Rare error. Occurs when the file cannot be opened to write to. This means ROBLOX Studio is lacking permission to open the file, or it is currently being opened exclusively by another process.

High-Level Overview:

The writefile function follows the already defined UNC specification. It will create or open a file at path and overwrite its contents with content.

Low-Level Overview:

For each transaction on the filesystem library, we open a handle to the file targeted by path. The content string is read from the Luau heap, and then content is written to the file using std::ios::trunc. Which will set the position of the cursor to the beginning of the file, regardless of anything, and truncate all contents; then it is written to, the buffer is flushed, and the handle is closed.

PreviousreadfileNextappendfile

Last updated 4 months ago