Repository navigation
files
Just in case, Niv comes with a simple file I/O API that allows you to create, read and write files.
Important to note: Files are opened by the API in text mode and not binary. It is only possible to open a file in input or output mode, but not both.
usage example:
// template
openfile path mode
// specific use
set file (openfile "res/dummy.txt" 'r')Args:
-
path:STR -
mode:CHAR
Desc:
This command has 2 modes and behaves differently in each:
-
r: opens an existing file at the specifiedpathand adds it to theinput filestack. -
w: opens an existing file in write mode, or creates a new one if the path doesn't exist, and adds it to theoutput filestack.
Important to note: path is relative to the path of the Niv executable, not the nst file.
Return value: VOID.
For more complex examples check files.nst
usage example:
// template
readbuf path
// specific use
set buffer (readbuf "res/dummy.txt" 'r')Args:
-
path:STR
Desc:
Reads the entirety of an already opened input file and returns it as a single STR.
Return value: STR.
For more complex examples check files.nst
usage example:
// template
writef path val trunc
// specific use
writef "res/dummy.txt" (cal 1 + 1) falseArgs:
-
path:STR -
val: Any value -
trunc:BOOL
Desc:
Writes val to an already opened output file at path, and erases all text inside the file before writing, if trunc is true.
Return value: VOID.
For more complex examples check files.nst
usage example:
// template
closef path
// specific use
closef "res/dummy.txt"Args:
-
path:STR
Desc:
Closes an opened file at path at either mode.
Return value: VOID.
For more complex examples check files.nst