gpt4 book ai didi

lua - Lua中隐式和显式io命名空间函数的区别

转载 作者:行者123 更新时间:2023-12-04 22:27:58 25 4
gpt4 key购买 nike

lua 中隐式函数和显式函数之间的确切区别是什么?我在阅读 Lua 中的文件操作时遇到了这些术语。隐式函数前面有 io.,如 io.read(),而显式函数看起来像 file :read()。尽管书上说了,但我对其中的区别一无所知

The difference between the two is that implicit functions work on the default file as provided by the io namespace, whereas explicit functions work with a file handle provided from a previous operation,such as io.open

有更好的解释吗?

最佳答案

io.read 从默认输入文件中读取。

默认输入文件是stdin,但您可以通过调用io.input 来更改它。

您还可以使用 io.open 显式打开文件,并在方法调用中使用返回的句柄,例如 f:read()

io.read() 等同于 io.input():read()

另见 http://www.lua.org/manual/5.2/manual.html#6.8 .

关于lua - Lua中隐式和显式io命名空间函数的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22859770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com