This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
playground:playground:zh [2023/11/26 22:26] hfsr |
playground:playground:zh [2023/11/29 05:01] hfsr |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{page>component:agent:zh#世界物品栏控制器特性API&noheader&nofooter}} | + | * 一个数字值,例如`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")` |