Written from a line-by-line source review; every example output is from a real run (Linux).
Introduction
The path plugin provides textual handling of file paths: you can safely join two path parts, extract the directory or the file name from a path, decide whether a path is absolute, and normalize a path (removing the redundant parts). The plugin performs purely textual operations — it does not touch the file system, and does not check whether the path exists. The plugin is stateless, every call is standalone.
Cross-platform separators
The plugin uses the running system's path separator: the slash (/) on Linux, the backslash (\) on Windows. Joining inserts the appropriate separator, and decomposition and inspection know both systems' rules. This reference's examples ran on Linux, so the outputs contain a slash.
Loading the plugin
plugin "../plugins/print/PrintPlugin"; plugin "../plugins/path/PathPlugin";
A typical flow — building and decomposing a path
string $full[256];
string $dir[256];
$full = path.Join("data/input", "image.png");
$dir = path.DirName($full);
printf("%s | %s\n", $full, $dir);What to know about every function (the basics)
Purely textual operations: the plugin does not touch the file system, and does not check whether the path points to an existing file/directory.
Join joins with the appropriate separator and does not double a redundant separator; if the relative part is absolute, it returns it unchanged.
DirName returns the directory part; if there is no directory component (just a file name), the “.” (current directory).
BaseName returns the last component, trimming the trailing separator(s).
IsAbsolute returns 1/0; Normalize resolves the “.” and “..” segments and collapses double separators.
An error (stopping the script) is caused only by a wrong argument count or type.
How to read the signatures
baseDir is a base directory, relativePath is a part to append to it, filePath/path is an arbitrary path. The type after the -> arrow is the return type. For example, path.Join(baseDir, relativePath) -> string takes two path parts and returns the joined path.
Joining
Safely joining two path parts with the appropriate separator.
path.Join
path.Join(baseDir, relativePath) -> string
Joins a base directory and a relative path with the system separator.
| Parameter | Type | Description |
|---|---|---|
| baseDir | string | The base directory (for empty or “.” it returns just the relative part). |
| relativePath | string | The part to append (if it is absolute, it is returned unchanged). |
The joined path. It does not double a redundant separator.
printf("%s\n", path.Join("a/b", "c.txt"));
printf("%s\n", path.Join("a/b/", "c.txt"));
printf("%s\n", path.Join("a", "/abs/x"));a/b/c.txt a/b/c.txt /abs/x
For safely building paths instead of manual string concatenation: it handles the separator correctly (does not omit or double it), and takes over an absolute relative part correctly too.
Decomposition
Extracting the directory or the file-name part from a path.
path.DirName
path.DirName(filePath) -> string
Extracts the path's directory part (the part before the last separator).
| Parameter | Type | Description |
|---|---|---|
| filePath | string | The path to decompose. |
The directory part. If there is no directory component (just a file name), the “.” (current directory).
printf("%s\n", path.DirName("/a/b/c.txt"));
printf("%s\n", path.DirName("c.txt"));/a/b .
To get a file's directory — for example to write another file into the same folder, or to create the directory structure.
path.BaseName
path.BaseName(filePath) -> string
Extracts the path's last component (the file or directory name).
| Parameter | Type | Description |
|---|---|---|
| filePath | string | The path to decompose. |
The last component (trimming the trailing separator(s)).
printf("%s\n", path.BaseName("/a/b/c.txt"));
printf("%s\n", path.BaseName("/a/b/"));c.txt b
To get the file name (or the innermost directory's name) — for example for display, logging, or further processing of the extension.
Inspection and normalization
Deciding whether a path is absolute and removing the redundant parts.
path.IsAbsolute
path.IsAbsolute(filePath) -> int
Tells whether the path is absolute (per the system's rules).
| Parameter | Type | Description |
|---|---|---|
| filePath | string | The path to inspect. |
1 if the path is absolute; otherwise 0.
printf("%d\n", path.IsAbsolute("/a/b"));
printf("%d\n", path.IsAbsolute("a/b"));1 0
To decide whether a path needs to be joined to a base directory (relative) or can be used on its own (absolute). On Windows it also recognizes the drive letter (C:\) and the network path.
path.Normalize
path.Normalize(path) -> string
Normalizes the path: resolves the “.” and “..” segments and collapses double separators.
| Parameter | Type | Description |
|---|---|---|
| path | string | The path to normalize. |
The normalized path (the redundant parts removed).
printf("%s\n", path.Normalize("a/./b/../c"));
printf("%s\n", path.Normalize("/a//b/"));a/c /a/b
To clean up paths and make them comparable — for example to simplify user input or joined paths before displaying them or using them as keys.
Practical notes
What the path plugin is good for
Safely building file paths instead of manual string concatenation (Join).
Extracting a path's parts: the directory (DirName) and the file name (BaseName).
Distinguishing relative and absolute paths (IsAbsolute).
Cleaning up and simplifying paths by removing the redundant parts (Normalize).
Text only — no file system
The path plugin performs purely textual operations: it does not open the file, does not check its existence, and does not resolve symbolic links. If you also want to know whether the path points to an existing file, use fileio.Exists. The two plugins complement each other well: path builds/decomposes the path, and fileio performs the actual file operation.
Cross-platform behavior
The plugin uses the running system's separator (Linux: /, Windows: \), and the inspections (IsAbsolute) know both systems' rules. So the same script produces the appropriate path form on both platforms. This reference's outputs were produced on Linux.
Error handling
The path functions report only a wrong argument count or type as a runtime error (the script then stops). Otherwise they always give a meaningful result: even for empty or unusual input a well-defined answer (for example DirName returns “.” if there is no directory part). Since there is no file-system access, there is no I/O error either.
The stdio standard I/O plugin
Writing to standard output and error, reading lines, and flushing — complete function reference