Content
Description:
The Content
record is a singleton object that manages file searching,
loading and other operations related to resources.
Usage:
local Content = require("Content")
local text = Content:load("filename.txt")
searchPaths
Type: Field.
Description:
An array of directories to search for resource files.
Signature:
searchPaths: {string}
assetPath
Type: Readonly Field.
Description:
The path to the directory containing read-only resources.
Signature:
const assetPath: string
writablePath
Type: Readonly Field.
Description:
The path to the directory where files can be written.
Signature:
const writablePath: string
load
Type: Function.
Description:
Loads the content of the file with the specified filename.
Signature:
load: function(self: Content, filename: string): string
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the file to load. |
Returns:
Return Type | Description |
---|---|
string | The content of the loaded file. |
loadExcel
Type: Function.
Description:
Loads the content of an Excel file with the specified filename and optional sheet names
Signature:
loadExcel: function(self: Content, filename: string, sheetNames?: {string}):
{
--[[sheetName]] string:
--[[rows]] {
--[[colums]] {string | number}
}
} | nil
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the Excel file to load |
sheetNames | {string} | [optional] An array of strings representing the names of the sheets to load. If not provided, all sheets will be loaded. |
Returns:
Return Type | Description |
---|---|
table | A table containing the data in the Excel file. The keys are the sheet names and the values are tables containing the rows and columns of the sheet. |
save
Type: Function.
Description:
Saves the specified content to a file with the specified filename.
Signature:
save: function(self: Content, filename: string, content: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the file to save. |
content | string | The content to save to the file. |
Returns:
Return Type | Description |
---|---|
boolean | true if the content saves to file successfully, false otherwise. |
exist
Type: Function.
Description:
Checks if a file with the specified filename exists.
Signature:
exist: function(self: Content, filename: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the file to check. |
Returns:
Return Type | Description |
---|---|
boolean | true if the file exists, false otherwise. |
mkdir
Type: Function.
Description:
Creates a new directory with the specified path.
Signature:
mkdir: function(self: Content, path: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The path of the directory to create. |
Returns:
Return Type | Description |
---|---|
boolean | true if the directory was created, false otherwise. |
isdir
Type: Function.
Description:
Checks if the specified path is a directory.
Signature:
isdir: function(self: Content, path: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The path to check. |
Returns:
Return Type | Description |
---|---|
boolean | true if the path is a directory, false otherwise. |
remove
Type: Function.
Description:
Removes the file or directory with the specified path.
Signature:
remove: function(self: Content, path: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The path of the file or directory to remove. |
Returns:
Return Type | Description |
---|---|
boolean | true if the file or directory was removed, false otherwise. |
copy
Type: Function.
Description:
Copies the file or directory in the specified path to target path.
Signature:
copy: function(self: Content, srcPath: string, dstPath: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
srcPath | string | The path of the file or directory to copy. |
dstPath | string | The path to copy files to. |
Returns:
Return Type | Description |
---|---|
boolean | true if the file or directory was copied to target path, false otherwise. |
move
Type: Function.
Description:
Moves the file or directory in the specified path to target path.
Signature:
move: function(self: Content, srcPath: string, dstPath: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
srcPath | string | The path of the file or directory to move. |
dstPath | string | The path to move files to. |
Returns:
Return Type | Description |
---|---|
boolean | true if the file or directory was moved to target path, false otherwise. |
isAbsolutePath
Type: Function.
Description:
Checks if the specified path is an absolute path.
Signature:
isAbsolutePath: function(self: Content, path: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The path to check. |
Returns:
Return Type | Description |
---|---|
boolean | true if the path is an absolute path, false otherwise. |
getFullPath
Type: Function.
Description:
Gets the full path of a file with the specified filename.
Signature:
getFullPath: function(self: Content, filename: string): string
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the file to get the full path of. |
Returns:
Return Type | Description |
---|---|
string | The full path of the file. |
insertSearchPath
Type: Function.
Description:
Inserts a search path at the specified index.
Signature:
insertSearchPath: function(self: Content, index: integer, path: string)
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index at which to insert the search path. |
path | string | The search path to insert. |
addSearchPath
Type: Function.
Description:
Adds a new search path to the end of the list.
Signature:
addSearchPath: function(self: Content, path: string)
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The search path to add. |
removeSearchPath
Type: Function.
Description:
Removes the specified search path from the list.
Signature:
removeSearchPath: function(self: Content, path: string)
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The search path to remove. |
loadAsync
Type: Function.
Description:
Asynchronously loads the content of the file with the specified filename.
Signature:
loadAsync: function(self: Content, filename: string): string
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the file to load. |
Returns:
Return Type | Description |
---|---|
string | The content of the loaded file. |
loadExcelAsync
Type: Function.
Description:
Asynchronously loads the content of an Excel file with the specified filename and optional sheet names.
Signature:
loadExcelAsync: function(self: Content, filename: string, sheetNames?: {string}):
{
--[[sheetName]] string:
--[[rows]] {
--[[colums]] {string | number}
}
} | nil
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the Excel file to load. |
sheetNames | {string} | [optional] An array of strings representing the names of the sheets to load. If not provided, all sheets will be loaded. |
Returns:
Return Type | Description |
---|---|
table | A table containing the data in the Excel file. The keys are the sheet names and the values are tables containing the rows and columns of the sheet. |
saveAsync
Type: Function.
Description:
Asynchronously saves the specified content to a file with the specified filename.
Signature:
saveAsync: function(self: Content, filename: string, content: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
filename | string | The name of the file to save. |
content | string | The content to save to the file. |
Returns:
Return Type | Description |
---|---|
boolean | true if the content was saved successfully, false otherwise. |
copyAsync
Type: Function.
Description:
Asynchronously copies a file or a folder from the source path to the destination path.
Signature:
copyAsync: function(self: Content, src: string, dst: string): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
src | string | The path of the file or folder to copy. |
dst | string | The destination path of the copied files. |
Returns:
Return Type | Description |
---|---|
boolean | true if the file or folder was copied successfully, false otherwise. |
zipAsync
Type: Function.
Description:
Asynchronously compresses the specified folder to a ZIP archive with the specified filename.
Signature:
zipAsync: function(self: Content, folderPath: string, zipFile: string, filter?: function(string): boolean): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
folderPath | string | The path of the folder to compress, should be under the asset writable path. |
zipFile | string | The name of the ZIP archive to create. |
filter | function | [optional] A function to filter the files to include in the archive. The function takes a filename as input and returns a boolean indicating whether to include the file. If not provided, all files will be included. |
Returns:
Return Type | Description |
---|---|
boolean | true if the folder was compressed successfully, false otherwise. |
unzipAsync
Type: Function.
Description:
Asynchronously decompresses a ZIP archive to the specified folder.
Signature:
unzipAsync: function(self: Content, zipFile: string, folderPath: string, filter?: function(string): boolean): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
zipFile | string | The name of the ZIP archive to decompress, should be a file under the asset writable path. |
folderPath | string | The path of the folder to decompress to, should be under the asset writable path. |
filter | function | [optional] A function to filter the files to include in the archive. The function takes a filename as input and returns a boolean indicating whether to include the file. If not provided, all files will be included. |
Returns:
Return Type | Description |
---|---|
boolean | true if the folder was decompressed successfully, false otherwise. |
getDirs
Type: Function.
Description:
Gets the names of all subdirectories in the specified directory.
Signature:
getDirs: function(self: Content, path: string): {string}
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The path of the directory to search. |
Returns:
Return Type | Description |
---|---|
table | An array of the names of all subdirectories in the specified directory. |
getFiles
Type: Function.
Description:
Gets the names of all files in the specified directory.
Signature:
getFiles: function(self: Content, path: string): {string}
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The path of the directory to search. |
Returns:
Return Type | Description |
---|---|
table | An array of the names of all files in the specified directory. |
getAllFiles
Type: Function.
Description:
Gets the names of all files in the specified directory and its subdirectories.
Signature:
getAllFiles: function(self: Content, path: string): {string}
Parameters:
Parameter | Type | Description |
---|---|---|
path | string | The path of the directory to search. |
Returns:
Return Type | Description |
---|---|
table | An array of the names of all files in the specified directory and its subdirectories. |
clearPathCache
Type: Function.
Description:
Clears the search path cache of the map of relative paths to full paths.
Signature:
clearPathCache: function(self: Content)