-
Notifications
You must be signed in to change notification settings - Fork 0
API Path
支持协议的路径值
Protocol-aware path value
Overview
Path 只处理路径文本:它规范化 /、点路径和协议路径,例如 mem://app/main.as,但不读取文件系统。静态方法通常返回字符串;实例方法会修改并返回同一个 Path。
Pathmanipulates path text only: it normalizes/, dot segments, and protocol paths such asmem://app/main.as, but never reads the file system. Static methods usually return strings; instance methods mutate and return the samePath.
Parameters:
-
root
根路径或Path。Root path or
Path. -
segments
零个或多个后续路径片段。Zero or more subsequent path segments.
Returns
已规范化的可变 Path。
Normalized mutable
Path.
var first = new Path("mem://app/scripts", "..", "main.as");
var second = Path.of("assets", "ui", "icon.png");
return first.toString() + ":" + second.toString();Parameters:
-
value
要检查的值。Value to inspect.
Returns
是否为 Path 对象。
Whether it is a
Pathobject.
return Path.isPath(new Path("scripts")); // trueParameters:
-
root
起始路径。Starting path.
-
segments
要拼接的路径片段。Path segments to join.
Returns
规范化路径字符串。
Normalized path string.
return Path.join("scripts", "shared", "main.as");Parameters:
-
segments
相对当前模块目录的路径片段。Path segments relative to the current module directory.
Returns
模块目录下的规范化路径;模块外为 null。
Normalized path below the module directory, or
nulloutside a module context.
@module(MAIN);
export func assetPath() {
return Path.baseModule("../assets", "config.json");
}Parameters:
-
path
路径文本或Path。Path text or
Path.
Returns
统一 / 和点片段后的文本。
Text with normalized
/and dot segments.
return Path.normalize("assets/../scripts/main.as"); // scripts/main.asParameters:
-
path
路径文本或Path。Path text or
Path.
Returns
父目录、最后片段或扩展名(含 .;没有扩展名时为空字符串)。
Parent directory, final segment, or extension (including
.; empty when absent).
var path = "assets/ui/icon.png";
return Path.directoryName(path) + ":" + Path.fileName(path) + ":" + Path.extName(path);Parameters:
-
path
路径文本或Path。Path text or
Path.
Returns
协议名(不带分隔符);普通路径为空字符串。
Protocol name without its separator; empty string for ordinary paths.
return Path.protocol("mem://app/main.as"); // memParameters:
-
path
原路径。Original path.
-
extension
新扩展名,可包含或省略.。New extension, with or without
..
Returns
更改扩展名后的规范化文本。
Normalized text with changed extension.
return Path.changeExt("scripts/main", "as"); // scripts/main.asParameters:
-
path
路径文本或Path。Path text or
Path.
Returns
是否为根路径或带协议路径。
Whether it is rooted or protocol-qualified.
return Path.isRooted("mem://app/main.as"); // trueParameters:
-
root
根路径。Root path.
-
path
待检查路径。Path to check.
Returns
规范化后是否位于根下。
Whether the normalized path is under the root.
return Path.isUnderRoot("scripts", "scripts/shared/main.as"); // trueParameters:
- 无。
None.
Returns
当前模块的完整路径或目录;模块外为 null。
Current module full path or directory, or
nulloutside a module context.
@module(MAIN);
export func currentLocation() {
return Path.currentFile() + ":" + Path.currentDirectory();
}Parameters:
-
segments
要追加的路径片段。Path segments to append.
Returns
当前 Path。
This
Path.
副作用
原地修改。
Mutates in place.
var path = new Path("assets");
return path.append("ui", "icon.png").toString();Parameters:
-
root
新根路径。New root path.
-
segments
后续路径片段。Subsequent path segments.
Returns
当前 Path。
This
Path.
副作用
用新路径替换旧路径。
Replaces the current path.
var path = new Path("old");
return path.reset("new", "main.as").toString();Parameters:
-
extension
新扩展名。New extension.
Returns
当前 Path。
This
Path.
副作用
原地更改扩展名。
Changes the extension in place.
var path = new Path("scripts/main");
return path.changeExt("as").toString();Parameters:
- 无。
None.
Returns
当前路径的父目录、最后片段、扩展名或协议。
Current path's parent directory, final segment, extension, or protocol.
var path = new Path("mem://app/main.as");
return path.directoryName() + ":" + path.fileName() + ":" + path.extName() + ":" + path.protocol();Parameters:
- 无。
None.
Returns
相同文本的新 Path。
New
Pathwith the same text.
var original = new Path("scripts/main.as");
var copy = original.clone();
copy.changeExt("json");
return original.toString(); // scripts/main.asParameters:
- 无。
None.
Returns
规范化路径文本。
Normalized path text.
return new Path("assets", "..", "scripts/main.as").toString();AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License