Luart
Comprehensive Windows framework to develop in Lua
modules > console > stdin

console.stdin read/write property

The console.stdin property gets the current standard console input file. It's a File value.

console.stdin redirection

Setting the console.stdin property to another File redirects console input to it : any further call to console.read() or console.stdout:read() will read input from that File. Closing the console.stdin property closes the current File and reuse the default console input File.

Example


local console = require "console"

-- create a file containing the unicode string "Hello World !"
local f = sys.File("hello.txt"):open("write", "unicode")
f:writeln("Hello World")
f:close()

console.stdin = f:open()

console.writeln("Hey, do you have anything to say ?")
local msg = console.readln()

--outputs "Ok, you said 'Hello World' !!!" without using your keyboard :)
console.writecolor("brown", "Ok, you said '"..msg.."' !!!\n")

-- closes "hello.txt" and revert back to standard console.stdin
console.stdin:close()