How do I get a value in Lua without using io.read ()?

1

Let's say I have something like

a = io.read()
a = tonumber(a)
if a then
    print(a,a^2-1)
end

Is there another way to get this input without being io.read() ?

    
asked by anonymous 13.11.2016 / 19:24

1 answer

1

Ready in the library is that right there. There are always several ways to get the same, but if you want to read from the console is the best way. Example:

local stdin = io.stdin:lines()
for line in stdin do
    print(line)
end

See working on ideone and on CodingGround .

If you want to read other sources you have several other ways. You have documentation .

    
13.11.2016 / 19:46