Getting input from the user in Lua

后端 未结 2 1154
粉色の甜心
粉色の甜心 2020-12-28 21:29

How can I get an input from user in Lua (like scanf in C)?
For example, the program ask user his name, then he writes his name, then the program will output

2条回答
  •  -上瘾入骨i
    2020-12-28 21:55

    Use io.read() Beware that the function can be customised with different parameters. Here are some examples.

     s = io.read("*n") -- read a number
     s = io.read("*l") -- read a line (default when no parameter is given)
     s = io.read("*a") -- read the complete stdin
     s = io.read(7) -- read 7 characters from stdin
     x,y = io.read(7,12) -- read 7 and 12 characters from stdin and assign them to x and y
     a,b = io.read("*n","*n") -- read two numbers and assign them to a and b
    

提交回复
热议问题