Filesystem
Read and write files in the Lynx workspace.
Every path is relative to the workspace folder. Scripts can't reach anything outside it, and can't write file types Windows would execute.
Files
readfile
since 1.0.0readfile(path: string): stringReturns the contents of the file at path. Errors if the file doesn't exist.
Parameters
pathstring- Path relative to the workspace.
Returns
stringThe file's contents. Binary-safe.
Example
writefile
since 1.0.0writefile(path: string, data: string): ()Writes data to path, replacing the file if it exists. Strings are binary-safe, so this works for images and other binary data too. Missing parent folders are created.
Parameters
pathstring- Path relative to the workspace.
datastring- The new contents.
Example
appendfile
since 1.0.0appendfile(path: string, data: string): ()Appends data to the end of the file at path, creating the file if it doesn't exist.
Parameters
pathstring- Path relative to the workspace.
datastring- The data to append.
Example
loadfile
since 1.0.0loadfile(path: string): (function?, string?)Compiles the file at path and returns it as a function without running it. On a syntax error, returns nil and the error message. Errors if the file doesn't exist.
Parameters
pathstring- Path relative to the workspace.
Returns
(function?, string?)The compiled chunk, or nil and an error.
Example
isfile
since 1.0.0isfile(path: string): booleanReturns whether a file exists at path. Returns false for folders.
Parameters
pathstring- Path relative to the workspace.
Returns
booleantrue if the file exists.
Example
delfile
since 1.0.0delfile(path: string): ()Deletes the file at path. The file is removed permanently and doesn't go to the Recycle Bin.
Parameters
pathstring- Path relative to the workspace.
Example
Folders
listfiles
since 1.0.0listfiles(path: string): {string}Returns the paths of every file and folder directly inside path. Returned paths are relative to the workspace, so you can pass them straight to other file functions. Pass "" for the workspace root.
Parameters
pathstring- Folder path relative to the workspace.
Returns
{string}Child paths.
Example
isfolder
since 1.0.0isfolder(path: string): booleanReturns whether a folder exists at path.
Parameters
pathstring- Path relative to the workspace.
Returns
booleantrue if the folder exists.
Example
makefolder
since 1.0.0makefolder(path: string): ()Creates a folder at path, including any missing parent folders. Does nothing if it already exists.
Parameters
pathstring- Path relative to the workspace.
Example
delfolder
since 1.0.0delfolder(path: string): ()Deletes the folder at path and everything inside it, permanently.
Parameters
pathstring- Path relative to the workspace.
Example
Written for Lynx 0.0.0
Something unclear? Tell us on Discord