瀏覽代碼

update docs

ruki 2 月之前
父節點
當前提交
87ee3fd23c

+ 21 - 12
docs/api/scripts/extension-modules/core/base/hashset.md

@@ -118,14 +118,17 @@ hashset:insert(value: <any>)
 |-----------|-------------|
 | value | Required. Element to insert |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| true | Element doesn't exist, insertion successful |
+| false | Element already exists, not inserted |
+
 #### Usage
 
 Inserts an element into the hash set. If the element already exists, it will not be inserted.
 
-Return value:
-- `true`: Element doesn't exist, insertion successful
-- `false`: Element already exists, not inserted
-
 ```lua
 local set = hashset.new()
 
@@ -166,14 +169,17 @@ hashset:remove(value: <any>)
 |-----------|-------------|
 | value | Required. Element to remove |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| true | Element exists, removal successful |
+| false | Element doesn't exist, not removed |
+
 #### Usage
 
 Removes an element from the hash set.
 
-Return value:
-- `true`: Element exists, removal successful
-- `false`: Element doesn't exist, not removed
-
 ```lua
 local set = hashset.of(1, 2, 3)
 
@@ -203,14 +209,17 @@ hashset:has(value: <any>)
 |-----------|-------------|
 | value | Required. Element to check |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| true | Element exists |
+| false | Element doesn't exist |
+
 #### Usage
 
 Checks if the specified element is in the hash set.
 
-Return value:
-- `true`: Element exists
-- `false`: Element doesn't exist
-
 Used for fast element lookup (O(1) time complexity):
 
 ```lua

+ 25 - 13
docs/api/scripts/extension-modules/core/base/pipe.md

@@ -187,14 +187,17 @@ Options:
 - `start`: Buffer start position, default 1
 - `timeout`: Timeout in milliseconds, default -1 (infinite wait)
 
+#### Return Values
+
+| Type | Description |
+|------|-------------|
+| read | Actual number of bytes read |
+| data | Read data (bytes object) |
+
 #### Usage
 
 Reads data from the pipe into the specified buffer.
 
-Return values:
-- `read`: Actual number of bytes read, returns -1 on failure
-- `data`: Read data (bytes object), returns error message on failure
-
 Non-blocking mode (default) returns immediately, may return 0 indicating no data available. Blocking mode waits until the specified amount of data is read or an error occurs:
 
 ```lua
@@ -233,13 +236,16 @@ Options:
 - `last`: Data end position, default is data size
 - `timeout`: Timeout in milliseconds, default -1
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| write | Actual number of bytes written |
+
 #### Usage
 
 Writes data to the pipe.
 
-Return values:
-- `write`: Actual number of bytes written, returns -1 on failure
-
 Non-blocking mode (default) may only write partial data. Blocking mode waits until all data is successfully written:
 
 ```lua
@@ -271,13 +277,16 @@ pipe:connect(opt: <table>)
 Options:
 - `timeout`: Timeout in milliseconds, default -1
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Returns a positive number |
+
 #### Usage
 
 Connects to a named pipe, only used on the server-side of named pipes. After creating a named pipe on the server, call this method to wait for client connection.
 
-Return values:
-- Returns a positive number on success, -1 on failure
-
 ```lua
 import("core.base.pipe")
 
@@ -312,13 +321,16 @@ Event constants:
 - `pipe.EV_WRITE` (2): Writable event, indicates pipe can accept data
 - `pipe.EV_CONN` (2): Connection event, used for named pipes to wait for client connection
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Returns the actual event constant value that occurred |
+
 #### Usage
 
 Waits for specified pipe events to occur. In non-blocking mode, this method can be used to implement event-driven I/O.
 
-Return values:
-- Returns the actual event constant value that occurred
-
 In non-blocking mode, wait can be used to implement efficient event loops:
 
 ```lua

+ 49 - 25
docs/api/scripts/extension-modules/core/base/scheduler.md

@@ -25,13 +25,16 @@ scheduler.co_start(cotask: <function>, ...)
 | cotask | Required. The coroutine task function to execute |
 | ... | Optional. Arguments to pass to the task function |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| coroutine | Returns coroutine object |
+
 #### Usage
 
 Start a new coroutine and execute the specified task function. The coroutine will start executing immediately unless the scheduler is not yet started.
 
-Return value:
-- Returns coroutine object on success, nil and error message on failure
-
 ```lua
 -- Start coroutine with arguments
 local co = scheduler.co_start(function(name, id)
@@ -142,13 +145,16 @@ scheduler.co_suspend()
 
 No parameters required for this function.
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| any | Returns arguments passed to `co_resume` |
+
 #### Usage
 
 Suspend the currently executing coroutine and yield execution to other coroutines.
 
-Return value:
-- Returns arguments passed to `co_resume`
-
 ```lua
 local co = scheduler.co_start(function()
     print("Step 1")
@@ -422,13 +428,16 @@ scheduler.co_running()
 
 No parameters required for this function.
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| coroutine | Current coroutine object (nil if no coroutine is running) |
+
 #### Usage
 
 Get the currently running coroutine object.
 
-Return value:
-- Current coroutine object, or nil if no coroutine is running
-
 ```lua
 -- Coroutine info example
 scheduler.co_start_named("info_task", function()
@@ -457,13 +466,16 @@ scheduler.co_count()
 
 No parameters required for this function.
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Number of coroutines |
+
 #### Usage
 
 Get the total number of active coroutines in the current scheduler.
 
-Return value:
-- Number of coroutines
-
 ```lua
 -- Coroutine counting example
 print("Initial count:", scheduler.co_count())
@@ -498,13 +510,16 @@ scheduler.co_semaphore(name: <string>, value: <number>)
 | name | Required. Semaphore name |
 | value | Optional. Initial semaphore value (default 0) |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| semaphore | Semaphore object |
+
 #### Usage
 
 Create a new coroutine semaphore for synchronization and resource control between coroutines.
 
-Return value:
-- Semaphore object
-
 ```lua
 -- Semaphore example
 local semaphore = scheduler.co_semaphore("resource", 3)  -- Allow up to 3 coroutines simultaneously
@@ -539,13 +554,16 @@ co_semaphore:wait(timeout: <number>)
 |-----------|-------------|
 | timeout | Optional. Timeout in milliseconds, -1 means wait indefinitely, 0 means don't wait |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Returns semaphore value |
+
 #### Usage
 
 Wait for the semaphore. If the semaphore value is greater than 0, return immediately; otherwise, suspend the current coroutine until the semaphore becomes available.
 
-Return value:
-- Returns semaphore value on success, 0 on timeout, -1 on error
-
 ```lua
 -- Semaphore wait example
 local semaphore = scheduler.co_semaphore("worker", 0)
@@ -586,13 +604,16 @@ co_semaphore:post(value: <number>)
 |-----------|-------------|
 | value | Required. The value to increase by |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | The new semaphore value after release |
+
 #### Usage
 
 Release the semaphore by increasing its value and wake up waiting coroutines.
 
-Return value:
-- The new semaphore value after release
-
 ```lua
 -- Semaphore post example
 local semaphore = scheduler.co_semaphore("batch", 0)
@@ -628,9 +649,12 @@ co_semaphore:name()
 
 No parameters required for this function.
 
-#### Usage
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| string | Semaphore name string |
 
-Get the semaphore name.
+#### Usage
 
-Return value:
-- Semaphore name string
+Get the semaphore name.

+ 52 - 22
docs/api/scripts/extension-modules/core/base/socket.md

@@ -313,12 +313,16 @@ socket:bind(addr: <string>, port: <number>)
 | addr | Required. IP address |
 | port | Required. Port number |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Returns a positive number |
+
 #### Usage
 
 Binds the socket to the specified IP address and port.
 
-Return value: Returns a positive number on success, -1 and error message on failure.
-
 ## socket:listen
 
 - Start listening for connections
@@ -364,12 +368,16 @@ socket:accept(opt: <table>)
 Options:
 - `timeout`: Timeout (milliseconds), default -1 (infinite wait)
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| socket | Returns client socket object |
+
 #### Usage
 
 Accepts a client connection, returns a new socket object for communicating with the client.
 
-Return value: Returns client socket object on success, nil and error message on failure.
-
 Non-blocking by default, returns immediately if no client is connecting. Can be used with [sock:wait](#sock-wait) for event-driven approach:
 
 ```lua
@@ -403,12 +411,16 @@ socket:connect(addr: <string>, port: <number>, opt: <table>)
 Options:
 - `timeout`: Connection timeout (milliseconds)
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Returns a positive number |
+
 #### Usage
 
 Connects to the specified remote address and port.
 
-Return value: Returns a positive number on success, -1 and error message on failure.
-
 ## socket:send
 
 - Send data
@@ -433,12 +445,16 @@ Options:
 - `start`: Data start position, default 1
 - `last`: Data end position, default is data size
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Actual number of bytes sent |
+
 #### Usage
 
 Sends data through the socket.
 
-Return value: Actual number of bytes sent, returns -1 on failure.
-
 Non-blocking mode may only send partial data, blocking mode waits until all data is sent:
 
 ```lua
@@ -476,14 +492,17 @@ Options:
 - `block`: Whether to block receiving, default false
 - `timeout`: Timeout (milliseconds)
 
+#### Return Values
+
+| Type | Description |
+|------|-------------|
+| recv | Actual number of bytes received |
+| data | Received data (bytes object) |
+
 #### Usage
 
 Receives data from the socket.
 
-Return values:
-- `recv`: Actual number of bytes received, returns -1 on failure
-- `data`: Received data (bytes object)
-
 ```lua
 import("core.base.bytes")
 
@@ -520,12 +539,16 @@ socket:sendto(data: <string|bytes>, addr: <string>, port: <number>, opt: <table>
 | port | Required. Target port number |
 | opt | Optional. Option parameters |
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Actual number of bytes sent |
+
 #### Usage
 
 Sends a datagram to the specified address via UDP socket.
 
-Return value: Actual number of bytes sent, returns -1 on failure.
-
 ```lua
 import("core.base.socket")
 
@@ -557,16 +580,19 @@ socket:recvfrom(buff: <bytes>, size: <number>, opt: <table>)
 Options:
 - `block`: Whether to block receiving
 
+#### Return Values
+
+| Type | Description |
+|------|-------------|
+| recv | Actual number of bytes received |
+| data | Received data (bytes object) |
+| peer_addr | Sender's IP address |
+| peer_port | Sender's port number |
+
 #### Usage
 
 Receives a datagram from the UDP socket and gets the sender's address information.
 
-Return values:
-- `recv`: Actual number of bytes received
-- `data`: Received data (bytes object)
-- `peer_addr`: Sender's IP address
-- `peer_port`: Sender's port number
-
 Complete UDP echo server example:
 
 ```lua
@@ -617,12 +643,16 @@ Supported event constants:
 - `socket.EV_CONN` (2): Connection event (equivalent to EV_SEND)
 - `socket.EV_ACPT` (1): Accept connection event (equivalent to EV_RECV)
 
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| number | Returns the actual event constant value that occurred |
+
 #### Usage
 
 Waits for specified socket events to occur.
 
-Return value: Returns the actual event constant value that occurred.
-
 Implementing event-driven in non-blocking mode:
 
 ```lua

+ 21 - 12
docs/zh/api/scripts/extension-modules/core/base/hashset.md

@@ -118,14 +118,17 @@ hashset:insert(value: <any>)
 |------|------|
 | value | 要插入的元素值 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| true | 元素不存在,插入成功 |
+| false | 元素已存在,未插入 |
+
 #### 用法说明
 
 向哈希集合插入一个元素。如果元素已存在,则不插入。
 
-返回值:
-- `true`:元素不存在,插入成功
-- `false`:元素已存在,未插入
-
 ```lua
 local set = hashset.new()
 
@@ -166,14 +169,17 @@ hashset:remove(value: <any>)
 |------|------|
 | value | 要删除的元素值 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| true | 元素存在,删除成功 |
+| false | 元素不存在,未删除 |
+
 #### 用法说明
 
 从哈希集合中删除一个元素。
 
-返回值:
-- `true`:元素存在,删除成功
-- `false`:元素不存在,未删除
-
 ```lua
 local set = hashset.of(1, 2, 3)
 
@@ -203,14 +209,17 @@ hashset:has(value: <any>)
 |------|------|
 | value | 要检查的元素值 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| true | 元素存在 |
+| false | 元素不存在 |
+
 #### 用法说明
 
 检查指定元素是否在哈希集合中。
 
-返回值:
-- `true`:元素存在
-- `false`:元素不存在
-
 用于快速查找元素(O(1) 时间复杂度):
 
 ```lua

+ 25 - 13
docs/zh/api/scripts/extension-modules/core/base/pipe.md

@@ -182,6 +182,13 @@ pipe:read(buff: <bytes>, size: <number>, opt: <table>)
 | size | 要读取的字节数 |
 | opt | 可选。选项参数 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| read | 实际读取的字节数 |
+| data | 读取的数据(bytes 对象) |
+
 #### 用法说明
 
 从管道读取数据到指定的缓冲区。
@@ -191,10 +198,6 @@ pipe:read(buff: <bytes>, size: <number>, opt: <table>)
 - `start`:缓冲区起始位置,默认 1
 - `timeout`:超时时间(毫秒),默认 -1(无限等待)
 
-返回值:
-- `read`:实际读取的字节数,失败返回 -1
-- `data`:读取的数据(bytes 对象),失败返回错误信息
-
 非阻塞模式(默认)会立即返回,可能返回 0 表示暂无数据。阻塞模式会等待直到读取到指定大小的数据或发生错误:
 
 ```lua
@@ -227,6 +230,12 @@ pipe:write(data: <string|bytes>, opt: <table>)
 | data | 要写入的数据,可以是字符串或 bytes 对象 |
 | opt | 可选。选项参数 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| write | 实际写入的字节数 |
+
 #### 用法说明
 
 向管道写入数据。
@@ -237,9 +246,6 @@ pipe:write(data: <string|bytes>, opt: <table>)
 - `last`:数据结束位置,默认为数据大小
 - `timeout`:超时时间(毫秒),默认 -1
 
-返回值:
-- `write`:实际写入的字节数,失败返回 -1
-
 非阻塞模式(默认)可能只写入部分数据。阻塞模式会等待直到所有数据都写入成功:
 
 ```lua
@@ -268,6 +274,12 @@ pipe:connect(opt: <table>)
 |------|------|
 | opt | 可选。选项参数 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 成功返回正数 |
+
 #### 用法说明
 
 连接命名管道,仅用于命名管道的服务端。在服务端创建命名管道后,需要调用此方法等待客户端连接。
@@ -275,9 +287,6 @@ pipe:connect(opt: <table>)
 选项参数说明:
 - `timeout`:超时时间(毫秒),默认 -1
 
-返回值:
-- 成功返回正数,失败返回 -1
-
 ```lua
 import("core.base.pipe")
 
@@ -307,6 +316,12 @@ pipe:wait(events: <number>, timeout: <number>)
 | events | 要等待的事件,支持事件常量 |
 | timeout | 超时时间(毫秒),-1 表示无限等待 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 返回实际发生的事件常量值 |
+
 #### 用法说明
 
 等待指定的管道事件发生。在非阻塞模式下,可以使用此方法实现事件驱动的 I/O。
@@ -318,9 +333,6 @@ pipe:wait(events: <number>, timeout: <number>)
   - `pipe.EV_CONN` (2):连接事件,用于命名管道等待客户端连接
 - `timeout`:超时时间(毫秒),-1 表示无限等待
 
-返回值:
-- 返回实际发生的事件常量值
-
 在非阻塞模式下,可以使用 wait 实现高效的事件循环:
 
 ```lua

+ 7 - 4
docs/zh/api/scripts/extension-modules/core/base/process.md

@@ -139,14 +139,17 @@ process:wait(timeout: <number>)
 |------|------|
 | timeout | 可选。超时时间(毫秒)。使用 -1 表示无限等待,0 表示非阻塞 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| ok | 退出代码(0 表示成功,负数表示错误) |
+| status | 进程状态或错误消息 |
+
 #### 用法说明
 
 等待子进程完成并返回退出状态。可以带或不带超时使用。
 
-返回值:
-- `ok` - 退出代码(0 表示成功,负数表示错误)
-- `status` - 进程状态或错误消息
-
 ```lua
 local proc = process.open("echo hello")
 local ok, status = proc:wait()

+ 48 - 24
docs/zh/api/scripts/extension-modules/core/base/scheduler.md

@@ -25,13 +25,16 @@ scheduler.co_start(cotask: <function>, ...)
 | cotask | 必需。要执行的协程任务函数 |
 | ... | 可选。传递给任务函数的参数 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| coroutine | 成功时返回协程对象 |
+
 #### 用法说明
 
 启动一个新的协程并执行指定的任务函数。协程会立即开始执行,除非调度器尚未启动。
 
-返回值:
-- 成功时返回协程对象,失败时返回 nil 和错误信息
-
 ```lua
 -- 启动带参数的协程
 local co = scheduler.co_start(function(name, id)
@@ -142,13 +145,16 @@ scheduler.co_suspend()
 
 此函数不需要参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| any | 返回传递给 `co_resume` 的参数 |
+
 #### 用法说明
 
 挂起当前正在执行的协程,让出执行权给其他协程。
 
-返回值:
-- 返回传递给 `co_resume` 的参数
-
 ```lua
 local co = scheduler.co_start(function()
     print("Step 1")
@@ -422,13 +428,16 @@ scheduler.co_running()
 
 此函数不需要参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| coroutine | 当前协程对象(如果没有运行中的协程则返回 nil) |
+
 #### 用法说明
 
 获取当前正在运行的协程对象。
 
-返回值:
-- 当前协程对象,如果没有运行中的协程则返回 nil
-
 ```lua
 -- 协程信息获取示例
 scheduler.co_start_named("info_task", function()
@@ -457,13 +466,16 @@ scheduler.co_count()
 
 此函数不需要参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 协程数量 |
+
 #### 用法说明
 
 获取当前调度器中活跃协程的总数。
 
-返回值:
-- 协程数量
-
 ```lua
 -- 协程计数示例
 print("Initial count:", scheduler.co_count())
@@ -498,13 +510,16 @@ scheduler.co_semaphore(name: <string>, value: <number>)
 | name | 必需。信号量名称 |
 | value | 可选。信号量初始值(默认为 0) |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| semaphore | 信号量对象 |
+
 #### 用法说明
 
 创建一个新的协程信号量,用于协程间的同步和资源控制。
 
-返回值:
-- 信号量对象
-
 ```lua
 -- 信号量示例
 local semaphore = scheduler.co_semaphore("resource", 3)  -- 最多允许 3 个协程同时访问
@@ -539,13 +554,16 @@ co_semaphore:wait(timeout: <number>)
 |------|------|
 | timeout | 可选。超时时间(毫秒),-1 表示无限等待,0 表示不等待 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 返回信号量值 |
+
 #### 用法说明
 
 等待信号量,如果信号量值大于 0 则立即返回,否则挂起当前协程直到信号量可用。
 
-返回值:
-- 成功时返回信号量值,超时时返回 0,错误时返回 -1
-
 ```lua
 -- 信号量等待示例
 local semaphore = scheduler.co_semaphore("worker", 0)
@@ -586,13 +604,16 @@ co_semaphore:post(value: <number>)
 |------|------|
 | value | 必需。要增加的值 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 释放后的信号量新值 |
+
 #### 用法说明
 
 释放信号量,增加信号量的值并唤醒等待的协程。
 
-返回值:
-- 释放后的信号量新值
-
 ```lua
 -- 信号量发布示例
 local semaphore = scheduler.co_semaphore("batch", 0)
@@ -628,9 +649,12 @@ co_semaphore:name()
 
 此函数不需要参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| string | 信号量名称字符串 |
+
 #### 用法说明
 
 获取信号量的名称。
-
-返回值:
-- 信号量名称字符串

+ 51 - 21
docs/zh/api/scripts/extension-modules/core/base/socket.md

@@ -313,12 +313,16 @@ socket:bind(addr: <string>, port: <number>)
 | addr | 必需。IP 地址 |
 | port | 必需。端口号 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 成功返回正数 |
+
 #### 用法说明
 
 将套接字绑定到指定的 IP 地址和端口。
 
-返回值:成功返回正数,失败返回 -1 和错误信息。
-
 ## socket:listen
 
 - 开始监听连接
@@ -361,16 +365,18 @@ socket:accept(opt: <table>)
 |------|------|
 | opt | 可选。选项参数 |
 
-#### 用法说明
-
-接受一个客户端连接,返回新的套接字对象用于与客户端通信。
-
 `opt` 选项:
 - `timeout`:超时时间(毫秒),默认 -1(无限等待)
 
-返回值:成功返回客户端套接字对象,失败返回 nil 和错误信息。
+#### 返回值说明
 
-默认是非阻塞的,如果没有客户端连接会立即返回。可配合 [sock:wait](#sock-wait) 实现事件驱动:
+| 类型 | 描述 |
+|------|------|
+| socket | 成功返回客户端套接字对象 |
+
+#### 用法说明
+
+接受一个客户端连接,返回新的套接字对象用于与客户端通信。默认是非阻塞的,如果没有客户端连接会立即返回。可配合 [sock:wait](#sock-wait) 实现事件驱动:
 
 ```lua
 -- 等待客户端连接
@@ -407,7 +413,11 @@ socket:connect(addr: <string>, port: <number>, opt: <table>)
 `opt` 选项:
 - `timeout`:连接超时时间(毫秒)
 
-返回值:成功返回正数,失败返回 -1 和错误信息。
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 成功返回正数 |
 
 ## socket:send
 
@@ -437,7 +447,11 @@ socket:send(data: <string|bytes>, opt: <table>)
 - `start`:数据起始位置,默认 1
 - `last`:数据结束位置,默认为数据大小
 
-返回值:实际发送的字节数,失败返回 -1。
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 实际发送的字节数 |
 
 非阻塞模式可能只发送部分数据,阻塞模式会等待直到所有数据发送完成:
 
@@ -480,9 +494,12 @@ socket:recv(buff: <bytes>, size: <number>, opt: <table>)
 - `block`:是否阻塞接收,默认 false
 - `timeout`:超时时间(毫秒)
 
-返回值:
-- `recv`:实际接收的字节数,失败返回 -1
-- `data`:接收的数据(bytes 对象)
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| recv | 实际接收的字节数 |
+| data | 接收的数据(bytes 对象) |
 
 ```lua
 import("core.base.bytes")
@@ -524,7 +541,11 @@ socket:sendto(data: <string|bytes>, addr: <string>, port: <number>, opt: <table>
 
 通过 UDP 套接字发送数据报到指定地址。
 
-返回值:实际发送的字节数,失败返回 -1。
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 实际发送的字节数 |
 
 ```lua
 import("core.base.socket")
@@ -561,11 +582,14 @@ socket:recvfrom(buff: <bytes>, size: <number>, opt: <table>)
 `opt` 选项:
 - `block`:是否阻塞接收
 
-返回值:
-- `recv`:实际接收的字节数
-- `data`:接收的数据(bytes 对象)
-- `peer_addr`:发送方 IP 地址
-- `peer_port`:发送方端口号
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| recv | 实际接收的字节数 |
+| data | 接收的数据(bytes 对象) |
+| peer_addr | 发送方 IP 地址 |
+| peer_port | 发送方端口号 |
 
 完整的 UDP 回显服务器示例:
 
@@ -621,9 +645,15 @@ socket:wait(events: <number>, timeout: <number>)
 - `socket.EV_CONN` (2):连接事件(等同于 EV_SEND)
 - `socket.EV_ACPT` (1):接受连接事件(等同于 EV_RECV)
 
-返回值:返回实际发生的事件常量值。
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 返回实际发生的事件常量值 |
+
+#### 用法说明
 
-在非阻塞模式下实现事件驱动:
+等待指定的套接字事件发生。在非阻塞模式下实现事件驱动:
 
 ```lua
 -- 等待套接字可读

+ 54 - 18
docs/zh/api/scripts/extension-modules/core/base/thread.md

@@ -21,12 +21,16 @@ thread.start(callback: <function>, ...)
 | callback | 必需。在线程中执行的回调函数 |
 | ... | 可选。传递给回调函数的额外参数 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| thread | 返回一个线程对象,可用于等待线程完成 |
+
 #### 用法说明
 
 创建并启动一个线程执行回调函数。
 
-返回值:返回一个线程对象,可用于等待线程完成
-
 ::: tip 注意
 每个线程都是单独的 Lua VM 实例,它们的 Lua 变量状态是完全隔离的,不能直接共享。参数传入是单向的,内部通过序列化方式传入,因此只支持 `string`、`table`、`number` 等支持序列化的参数。
 :::
@@ -51,12 +55,16 @@ thread.start_named(name: <string>, callback: <function>, ...)
 | callback | 必需。在线程中执行的回调函数 |
 | ... | 可选。传递给回调函数的额外参数 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| thread | 返回一个线程对象,可用于等待线程完成 |
+
 #### 用法说明
 
 创建并启动一个具有指定名称和回调函数的新线程。
 
-返回值:返回一个线程对象,可用于等待线程完成
-
 ::: tip 注意
 参数传入是单向的,内部通过序列化方式传入,因此只支持 `string`、`table`、`number` 等支持序列化的参数。
 :::
@@ -100,12 +108,16 @@ thread.running()
 
 无参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| string | 返回当前线程的名称字符串 |
+
 #### 用法说明
 
 返回当前运行线程的名称。
 
-返回值:返回当前线程的名称字符串
-
 ## thread.mutex
 
 - 创建互斥锁对象
@@ -122,12 +134,16 @@ thread.mutex()
 
 无参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| mutex | 返回一个互斥锁对象,具有以下方法:mutex:lock() 锁定互斥锁,mutex:unlock() 解锁互斥锁 |
+
 #### 用法说明
 
 创建一个新的互斥锁用于线程同步。
 
-返回值:返回一个互斥锁对象,具有以下方法:`mutex:lock()` 锁定互斥锁,`mutex:unlock()` 解锁互斥锁
-
 ::: tip 注意
 互斥锁可以跨线程访问,用于线程间同步。
 :::
@@ -174,12 +190,16 @@ thread.event()
 
 无参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| event | 返回一个事件对象,具有以下方法:event:wait(timeout) 等待事件信号,event:post() 发送事件信号 |
+
 #### 用法说明
 
 创建一个新的事件用于线程信号和同步。
 
-返回值:返回一个事件对象,具有以下方法:`event:wait(timeout)` 等待事件信号,`event:post()` 发送事件信号
-
 ::: tip 注意
 事件对象可以跨线程访问,用于线程间信号通信。
 :::
@@ -232,12 +252,16 @@ thread.semaphore(name: <string>, initial_count: <number>)
 | name | 必需。信号量名称 |
 | initial_count | 必需。初始计数值 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| semaphore | 返回一个信号量对象,具有以下方法:semaphore:wait(timeout) 等待信号量(减少计数),semaphore:post(count) 发送信号量(增加计数) |
+
 #### 用法说明
 
 创建一个新的信号量用于线程同步和资源计数。
 
-返回值:返回一个信号量对象,具有以下方法:`semaphore:wait(timeout)` 等待信号量(减少计数),`semaphore:post(count)` 发送信号量(增加计数)
-
 ::: tip 注意
 信号量可以跨线程访问,用于线程间资源计数和同步。
 :::
@@ -287,12 +311,16 @@ thread.queue()
 
 无参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| queue | 返回一个队列对象,具有以下方法:queue:push(value) 向队列推送值,queue:pop() 从队列弹出值,queue:empty() 检查队列是否为空 |
+
 #### 用法说明
 
 创建一个新的线程安全队列用于线程间数据通信。
 
-返回值:返回一个队列对象,具有以下方法:`queue:push(value)` 向队列推送值,`queue:pop()` 从队列弹出值,`queue:empty()` 检查队列是否为空
-
 ::: tip 注意
 队列是线程间数据通信的主要方式,支持跨线程访问。
 :::
@@ -345,12 +373,16 @@ thread.sharedata()
 
 无参数。
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| sharedata | 返回一个共享数据对象,具有以下方法:sharedata:set(value) 设置共享数据值,sharedata:get() 获取共享数据值 |
+
 #### 用法说明
 
 创建一个新的共享数据对象用于线程间数据共享。
 
-返回值:返回一个共享数据对象,具有以下方法:`sharedata:set(value)` 设置共享数据值,`sharedata:get()` 获取共享数据值
-
 ::: tip 注意
 共享数据对象是线程间数据共享的主要方式,支持跨线程访问。
 :::
@@ -403,12 +435,16 @@ thread:wait(timeout: <number>)
 |------|------|
 | timeout | 必需。超时时间(毫秒),-1表示无限等待 |
 
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| number | 返回表示等待结果的状态码 |
+
 #### 用法说明
 
 等待线程完成执行。此方法支持与协程混合调度,可以在协程中等待线程完成。
 
-返回值:返回表示等待结果的状态码
-
 示例(线程与协程混合调度):
 
 ```lua