Browse Source

update docs

ruki 2 months ago
parent
commit
eba583ec6a

+ 168 - 13
docs/api/scripts/builtin-modules/os.md

@@ -1505,10 +1505,21 @@ os.setenv("PATH", "/new/path:" .. os.getenv("PATH"))
 
 - Add values to one environment variable
 
+#### Function Prototype
+
 ```lua
-os.addenv("PATH", "/new/path")
+os.addenv(name: <string>, value: <string>)
 ```
 
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| name | Environment variable name |
+| value | Value to add |
+
+#### Usage
+
 Appends a new value to the specified environment variable, using the system default separator (`:` on Unix, `;` on Windows).
 
 ```lua
@@ -1523,26 +1534,62 @@ print(os.getenv("PATH"))  -- New path will be appended to existing PATH
 
 - Setting environment variables with a given separator
 
+#### Function Prototype
+
 ```lua
-os.setenvp("VAR", "value", "separator")
+os.setenvp(name: <string>, value: <string>, separator: <string>)
 ```
 
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| name | Environment variable name |
+| value | Environment variable value |
+| separator | Separator string |
+
+#### Usage
+
 Sets an environment variable using a specified separator. Similar to [os.setenv](#os-setenv), but allows custom separator.
 
 ## os.addenvp
 
 - Add values to one environment variable with a given separator
 
+#### Function Prototype
+
 ```lua
-os.addenvp("VAR", "value", "separator")
+os.addenvp(name: <string>, value: <string>, separator: <string>)
 ```
 
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| name | Environment variable name |
+| value | Value to add |
+| separator | Separator string |
+
+#### Usage
+
 Appends a value to an environment variable using a specified separator. Similar to [os.addenv](#os-addenv), but allows custom separator.
 
 ## os.workingdir
 
 - Get the working directory
 
+#### Function Prototype
+
+```lua
+os.workingdir()
+```
+
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 ```lua
 local workdir = os.workingdir()
 ```
@@ -1557,12 +1604,18 @@ print("Working directory:", os.workingdir())
 
 - Test if xmake is running as root
 
+#### Function Prototype
+
 ```lua
-if os.isroot() then
-    print("Running as root/administrator")
-end
+os.isroot()
 ```
 
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 On Unix systems, checks if running as root user; on Windows, checks if running with administrator privileges.
 
 Useful when certain operations require administrator privileges:
@@ -1577,14 +1630,18 @@ end
 
 - Test if the os has a case sensitive filesystem
 
+#### Function Prototype
+
 ```lua
-if os.fscase() then
-    print("Filesystem is case-sensitive")
-else
-    print("Filesystem is case-insensitive")
-end
+os.fscase()
 ```
 
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 Returns true if the filesystem is case-sensitive (like Linux), false if not (like Windows, macOS default).
 
 Useful for handling cross-platform filename compatibility:
@@ -1600,6 +1657,18 @@ end
 
 - Get current terminal (windows-terminal, vscode, ... )
 
+#### Function Prototype
+
+```lua
+os.term()
+```
+
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 ```lua
 print(os.term())
 -- got vscode
@@ -1609,6 +1678,18 @@ print(os.term())
 
 - Get current shell  (pwsh, cmd, ...)
 
+#### Function Prototype
+
+```lua
+os.shell()
+```
+
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 ```lua
 print(os.shell())
 -- got pwsh
@@ -1618,6 +1699,20 @@ print(os.shell())
 
 - Get cpu information
 
+#### Function Prototype
+
+```lua
+os.cpuinfo(key: <string>)
+```
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| key | CPU info key (optional) |
+
+#### Usage
+
 ```lua
 print(os.cpuinfo())
 -- got {
@@ -1636,6 +1731,20 @@ print(os.cpuinfo("march")) -- got "Kaby Lake"
 
 - Get memory information
 
+#### Function Prototype
+
+```lua
+os.meminfo(key: <string>)
+```
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| key | Memory info key (optional) |
+
+#### Usage
+
 ```lua
 print(os.meminfo())
 -- got {
@@ -1650,6 +1759,18 @@ print(os.meminfo())
 
 - Get default parallel jobs
 
+#### Function Prototype
+
+```lua
+os.default_njob()
+```
+
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 Returns the default number of parallel compilation jobs, typically equal to the number of CPU cores.
 
 ```lua
@@ -1661,10 +1782,21 @@ print("Default parallel jobs:", njob)
 
 - Parse command line string into argument list
 
+#### Function Prototype
+
 ```lua
-local args = os.argv("gcc -o test test.c -I/usr/include")
+os.argv(command: <string>, options: <table>)
 ```
 
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| command | Command line string |
+| options | Options table (optional) |
+
+#### Usage
+
 Parses a command line string into an argument array, supporting quotes, escape characters, and other complex formats.
 
 Parsing rules:
@@ -1702,10 +1834,21 @@ os.argv('-DTEST="hello world"', {splitonly = true})  -- Returns: {'-DTEST="hello
 
 - Convert argument list to command line string
 
+#### Function Prototype
+
 ```lua
-local cmdline = os.args({"gcc", "-o", "test", "test.c"})
+os.args(args: <table>, options: <table>)
 ```
 
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| args | Arguments array |
+| options | Options table (optional) |
+
+#### Usage
+
 Converts an argument array to a command line string, the inverse operation of [os.argv](#os-argv).
 
 Automatically handles special characters:
@@ -1748,6 +1891,18 @@ local cmdline2 = os.args(args)
 
 - Get monotonic clock time (milliseconds)
 
+#### Function Prototype
+
+```lua
+os.mclock()
+```
+
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 ```lua
 local start = os.mclock()
 -- Perform some operations

+ 58 - 0
docs/api/scripts/extension-modules/async/jobgraph.md

@@ -6,6 +6,18 @@ This module provides a job graph (DAG) for advanced asynchronous job scheduling
 
 - Create a new job graph instance.
 
+#### Function Prototype
+
+```lua
+jobgraph.new()
+```
+
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Usage
+
 ```lua
 import("async.jobgraph")
 local jobs = jobgraph.new()
@@ -17,6 +29,22 @@ local jobs = jobgraph.new()
 
 - Add a job node to the job graph.
 
+#### Function Prototype
+
+```lua
+jobgraph:add(name: <string>, jobfunc: <function>, options: <table>)
+```
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| name | Job name string |
+| jobfunc | Job function |
+| options | Options table (optional) |
+
+#### Usage
+
 ```lua
 local jobs = jobgraph.new()
 jobs:add("job/root", function() print("root job") end)
@@ -66,6 +94,21 @@ rule("foo")
 
 - Add dependency orders.
 
+#### Function Prototype
+
+```lua
+jobgraph:add_orders(jobname: <string>, ...)
+```
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| jobname | Job name string |
+| ... | Variable arguments for dependency jobs |
+
+#### Usage
+
 ```lua
 local jobs = jobgraph.new()
 jobs:add("job/root", function() print("root job") end)
@@ -77,6 +120,21 @@ jobs:add_orders("job/child", "job/root")
 
 - Group jobs for batch dependency management. You can use a callback to add jobs to a group.
 
+#### Function Prototype
+
+```lua
+jobgraph:group(groupname: <string>, callback: <function>)
+```
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| groupname | Group name string |
+| callback | Callback function to add jobs to group |
+
+#### Usage
+
 ```lua
 local jobs = jobgraph.new()
 

+ 16 - 0
docs/api/scripts/extension-modules/async/runjobs.md

@@ -6,6 +6,22 @@ This module runs all jobs in a job graph concurrently, respecting dependencies.
 
 Run all jobs in the job graph concurrently.
 
+#### Function Prototype
+
+```lua
+runjobs(name: <string>, jobs: <jobgraph>, options: <table>)
+```
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| name | Job name string |
+| jobs | Job graph instance |
+| options | Options table |
+
+#### Usage
+
 - `comax`: Maximum number of concurrent jobs.
 - `timeout`: Timeout for each job (ms).
 - `timer`: Timer callback for monitoring running jobs.

+ 103 - 15
docs/zh/api/scripts/builtin-modules/os.md

@@ -1502,12 +1502,18 @@ print("工作目录:", os.workingdir())
 
 - 判断xmake是否以管理员权限运行
 
+#### 函数原型
+
 ```lua
-if os.isroot() then
-    print("以管理员权限运行")
-end
+os.isroot()
 ```
 
+#### 参数说明
+
+此函数不需要参数。
+
+#### 用法说明
+
 在 Unix 系统上检查是否以 root 用户运行,在 Windows 上检查是否以管理员权限运行。
 
 某些操作需要管理员权限时很有用:
@@ -1522,14 +1528,18 @@ end
 
 - 判断操作系统的文件系统是否大小写敏感
 
+#### 函数原型
+
 ```lua
-if os.fscase() then
-    print("文件系统区分大小写")
-else
-    print("文件系统不区分大小写")
-end
+os.fscase()
 ```
 
+#### 参数说明
+
+此函数不需要参数。
+
+#### 用法说明
+
 返回 true 表示文件系统区分大小写(如 Linux),false 表示不区分(如 Windows、macOS 默认)。
 
 用于处理跨平台的文件名兼容性:
@@ -1545,9 +1555,35 @@ end
 
 - 获取当前终端 (windows-terminal, vscode, xterm, ...)
 
+#### 函数原型
+
+```lua
+os.term()
+```
+
+#### 参数说明
+
+此函数不需要参数。
+
+#### 用法说明
+
 ## os.shell
 
-- 获取当前shell (pwsh, cmd, bash, zsh, ...)
+- 获取当前shell
+
+#### 函数原型
+
+```lua
+os.shell()
+```
+
+#### 参数说明
+
+此函数不需要参数。
+
+#### 用法说明
+
+获取当前使用的 shell 程序名称,支持多种 shell 类型如 pwsh, cmd, bash, zsh 等。
 
 ## os.cpuinfo
 
@@ -1571,6 +1607,20 @@ print(os.cpuinfo("march")) -- probably got "Alder Lake"
 
 - 获取内存信息
 
+#### 函数原型
+
+```lua
+os.meminfo(key: <string>)
+```
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| key | 内存信息键名(可选) |
+
+#### 用法说明
+
 ```lua
 print(os.meminfo())
 -- probably got {
@@ -1586,6 +1636,18 @@ print(os.meminfo("pagesize")) -- probably got 4096
 
 - 获取默认编译任务数
 
+#### 函数原型
+
+```lua
+os.default_njob()
+```
+
+#### 参数说明
+
+此函数不需要参数。
+
+#### 用法说明
+
 返回默认的并行编译任务数,通常等于 CPU 核心数。
 
 ```lua
@@ -1597,10 +1659,20 @@ print("默认并行任务数:", njob)
 
 - 将命令行字符串解析为参数列表
 
+#### 函数原型
+
 ```lua
-local args = os.argv("gcc -o test test.c -I/usr/include")
+os.argv(command: <string>)
 ```
 
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| command | 命令行字符串 |
+
+#### 用法说明
+
 将命令行字符串解析为参数数组,支持引号、转义字符等复杂格式。
 
 解析规则:
@@ -1638,10 +1710,21 @@ os.argv('-DTEST="hello world"', {splitonly = true})  -- 返回: {'-DTEST="hello
 
 - 将参数列表转换为命令行字符串
 
+#### 函数原型
+
 ```lua
-local cmdline = os.args({"gcc", "-o", "test", "test.c"})
+os.args(args: <table>, options: <table>)
 ```
 
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| args | 参数数组 |
+| options | 选项表(可选) |
+
+#### 用法说明
+
 将参数数组转换为命令行字符串,是 [os.argv](#os-argv) 的逆操作。
 
 自动处理特殊字符:
@@ -1684,13 +1767,18 @@ local cmdline2 = os.args(args)
 
 - 获取单调时钟时间(毫秒)
 
+#### 函数原型
+
 ```lua
-local start = os.mclock()
--- 执行一些操作
-local elapsed = os.mclock() - start
-print("耗时:", elapsed, "ms")
+os.mclock()
 ```
 
+#### 参数说明
+
+此函数不需要参数。
+
+#### 用法说明
+
 返回单调递增的时间戳(毫秒),适合用于测量时间间隔。
 
 与 `os.clock()` 不同,`os.mclock()` 返回的是单调时钟,不受系统时间调整的影响,更适合用于性能测量:

+ 58 - 0
docs/zh/api/scripts/extension-modules/async/jobgraph.md

@@ -6,6 +6,18 @@
 
 - 创建新的任务图实例。
 
+#### 函数原型
+
+```lua
+jobgraph.new()
+```
+
+#### 参数说明
+
+此函数不需要参数。
+
+#### 用法说明
+
 ```lua
 import("async.jobgraph")
 local jobs = jobgraph.new()
@@ -17,6 +29,22 @@ local jobs = jobgraph.new()
 
 - 向任务图添加一个任务节点。
 
+#### 函数原型
+
+```lua
+jobgraph:add(name: <string>, jobfunc: <function>, options: <table>)
+```
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| name | 任务名称字符串 |
+| jobfunc | 任务函数 |
+| options | 选项表(可选) |
+
+#### 用法说明
+
 ```lua
 local jobs = jobgraph.new()
 jobs:add("job/root", function() print("root job") end)
@@ -66,6 +94,21 @@ rule("foo")
 
 - 添加依赖执行顺序
 
+#### 函数原型
+
+```lua
+jobgraph:add_orders(jobname: <string>, ...)
+```
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| jobname | 任务名称字符串 |
+| ... | 依赖任务的可变参数 |
+
+#### 用法说明
+
 ```lua
 local jobs = jobgraph.new()
 jobs:add("job/root", function() print("root job") end)
@@ -77,6 +120,21 @@ jobs:add_orders("job/child", "job/root")
 
 - 分组批量管理任务依赖。可通过回调批量添加分组任务
 
+#### 函数原型
+
+```lua
+jobgraph:group(groupname: <string>, callback: <function>)
+```
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| groupname | 分组名称字符串 |
+| callback | 向分组添加任务的回调函数 |
+
+#### 用法说明
+
 ```lua
 local jobs = jobgraph.new()
 

+ 16 - 0
docs/zh/api/scripts/extension-modules/async/runjobs.md

@@ -6,6 +6,22 @@
 
 并发执行任务图中的所有任务。
 
+#### 函数原型
+
+```lua
+runjobs(name: <string>, jobs: <jobgraph>, options: <table>)
+```
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| name | 任务名称字符串 |
+| jobs | 任务图实例 |
+| options | 选项表 |
+
+#### 用法说明
+
 - `comax`: 最大并发任务数
 - `timeout`: 单个任务超时时间(毫秒)
 - `timer`: 定时回调,可用于监控当前运行中的任务