Skip to main content

Path

Description:

  Helper class for file path operations.

getScriptPath

Type: Function.

Description:

  Gets script running path from a module name.

Signature:

getScriptPath: function(self: Path, moduleName: string): string

Usage:

-- in the script entry file named 'init'
local scriptPath = Path:getScriptPath(...)
-- set up the project search paths
Content:insertSearchPath(1, scriptPath)

Parameters:

ParameterTypeDescription
moduleNamestringThe input module name.

Returns:

Return TypeDescription
stringThe module path for script searching.

getExt

Type: Function.

Description:

  Input: /a/b/c.TXT output: txt

Signature:

getExt: function(self: Path, path: string): string

Parameters:

ParameterTypeDescription
pathstringThe input file path.

Returns:

Return TypeDescription
stringThe input file's extension.

getPath

Type: Function.

Description:

  Input: /a/b/c.TXT output: /a/b

Signature:

getPath: function(self: Path, path: string): string

Parameters:

ParameterTypeDescription
pathstringThe input file path.

Returns:

Return TypeDescription
stringThe input file's parent path.

getName

Type: Function.

Description:

  Input: /a/b/c.TXT output: c

Signature:

getName: function(self: Path, path: string): string

Parameters:

ParameterTypeDescription
pathstringThe input file path.

Returns:

Return TypeDescription
stringThe input file's name without extension.

getFilename

Type: Function.

Description:

  Input: /a/b/c.TXT output: c.TXT

Signature:

getFilename: function(self: Path, path: string): string

Parameters:

ParameterTypeDescription
pathstringThe input file path.

Returns:

Return TypeDescription
stringThe input file's name.

getRelative

Type: Function.

Description:

  Input: /a/b/c.TXT, base: /a output: b/c.TXT

Signature:

getRelative: function(self: Path, path: string, base: string): string

Parameters:

ParameterTypeDescription
pathstringThe input file path.
basestringThe target file path.

Returns:

Return TypeDescription
stringThe relative from input file to target file.

replaceExt

Type: Function.

Description:

  Input: /a/b/c.TXT, lua output: /a/b/c.lua

Signature:

replaceExt: function(self: Path, path: string, newExt: string): string

Parameters:

ParameterTypeDescription
pathstringThe input file path.
newExtstringThe new file extention to add to file path.

Returns:

Return TypeDescription
stringThe new file path.

replaceFilename

Type: Function.

Description:

  Input: /a/b/c.TXT, d output: /a/b/d.TXT

Signature:

replaceFilename: function(self: Path, path: string, newFile: string): string

Parameters:

ParameterTypeDescription
pathstringThe input file path.
newFilestringThe new filename to replace.

Returns:

Return TypeDescription
stringThe new file path.

__call

Type: Metamethod.

Description:

  input: a, b, c.TXT output: a/b/c.TXT

Signature:

metamethod __call: function(self: Path, ...: string): string

Parameters:

ParameterTypeDescription
...stringThe segments to be joined as a new file path.

Returns:

Return TypeDescription
stringThe new file path.