Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
playground:playground:zh [2023/11/26 22:26]
hfsr
playground:playground:zh [2023/11/29 05:21] (current)
hfsr
Line 1: Line 1:
-{{page>​component:agent:zh#机器人组件API&​noheader&​nofooter}}+ 
 +- `b:read([formats...]) string...` ​  
 +  先进的读取器,可支持多种格式。首先,如果不指定`format`调用,即参数列表留空,它会从流中读取下一行,等价于`read("​*l"​)`。 ​  
 +每个`format`值都会先从IO流中读出,再一次性以多个返回值的形式返回。请注意格式字符串都有 \* 前缀,而且只有字符串的第一个字符有意义,其余字符将会被忽略。 ​  
 +  下列是支持的格式: ​  
 +  * 一个数字值,例如`10` ​  
 +  从IO流读取**n**个字节(以二进制模式)或字符(以文本模式),结果将以字符串形式返回。参见[[api:non-standard-lua-libs#input_and_output_facilities|io.open]]以获取有关如何以不同模式打开文件的更多信息。 ​  
 +  示例:`local chars = b:​read(10)` ​  
 +\\ 
 +  * `*n`或者`*number` ​  
 +  从IO流中读取下一可被解释为数字的字节。请注意读取到的数字会受到打开模式为二进制还是文本的影响。参见[[api:​non-standard-lua-libs#​input_and_output_facilities|io.open]]以获取有关如何以不同模式打开文的更多信息。 ​  
 +  示例:`local number = b:​read("​*n"​)` ​  
 +\\ 
 +  * `*l`或者`*line` ​  
 +  从IO流中读取下一行,截掉换行标记(可能是 \n,​、\r或\r\n)。 ​  
 +  示例:`local line = b:​read("​*l"​)` ​  
 +\\ 
 +  * `*L`或者`*Line` ​  
 +  从IO流中读取下一行,类似`*line`,但是在结果中保留换行标记。 ​  
 +  示例:`local whole_line = b:​read("​*L"​)` ​  
 +\\ 
 +  * `*a`或者`*all` ​  
 +  从IO流中读取所有剩余内容,直到遇到nil。在此读取格式后再指定其他格式没有意义。 ​  
 +  示例:`local the_whole_file = b:​read("​*a"​)`\\ 
 +  \\ 
 +- `b:​getTimeout() number` ​  
 +  返回当前带缓冲流设定的超时时间(单位为秒)。默认超时时间为`math.huge`。参阅`setTimeout`以获取有关于带缓冲流超时时间影响的更多信息。 ​  
 +\\