Lua plugins in Vocode cannot access the Lua standard library
For security, plugins can only access core libraries and those tied to granted permissions.
📄 file.open(settingName, applyTemplateFn)
Opens a file for reading or writing based on the provided settings item, applying a template function to modify the file name if provided. (Creates the specified file if it does not already exist)
Parameters
-
settingName
(string): The setting key for the file path in theexporterItem
. -
applyTemplateFn
(string, optional): The name of the function to modify the file name.
Example
file.open("settings", "templateFunction")
📑 file.setPosition(position)
Sets the file read/write position to the specified value
Parameters
position
(number): The position to set in the file.
Example
file.setPosition(100)
file.getPosition() → num
Gets the current position in the file
Example
file.getPosition() // -> 100
file.getLength() → num
Gets the length of the file
Example
file.getLength() // -> 100
file.readForwardLine() → str
Reads a line of text forward from the current file position
Example
file.readForwardLine() // -> "Hello World!!!"
file.readBackwardLine() → str
Reads a line of text backward from the current file position
Example
file.readBackwardLine() // -> "Hello World!!!"
file.read(length)
Reads a specified number of bytes from the file
Example
file.read(50)
📝 file.writeString(string)
Writes a string to the file
Parameters
string
(string): The string to write to the file.
Example
file.writeString("Hello, world!")
file.countBytes(string) → int
Counts the number of bytes in a given string
Parameters
string
(string): The string to count bytes for.
Example
file.countBytes("Hello") // -> 5
file.truncate(length)
Truncates the file to a specific length
Parameters
length
(number): The length to truncate the file to.
Example
file.truncate(100)
📃 file.close(applyTemplateFn)
Closes the file and optionally applies a template function to modify the file name before saving
Parameters
applyTemplateFn
(string, optional): The name of the function to modify the file name before saving.
Example
file.close("templateFunction")