有没有办法将流重定向到 lua 中的标准输入

is there a way to redirect stream to stdin in lua

所以我尝试使用以下方法读取文件

file=io.open('test.txt', 'r')
io.input(file)
a=io.read()
print(a)
io.close(file)

问题是,我真的不知道如何将 io.read 重定向回标准输入流。我试过了:

io.input(stdin)
a=io.read()
print(a)

有什么方法可以实现吗?

编辑: 通过暗示 io.stdin 而不是 stdin

解决了问题

您可以调用 io.input(io.stdin) 设置默认标准输入。

Lua 实际上允许 file:read() 而不是将流定向到标准输入,这使我们能够直接从文件中读取。