As the title said:
Is there an Equivalent scanf function in Lua?
I mean, I want to have a syntax like this:
word_typed = lua_scanf()
Run Code Online (Sandbox Code Playgroud)
一旦我写了一个字符串(让我们说"123是完整的数字"),我就有了字符串"123 is perfect number".
提前谢谢了
PS如果需要,您可以根据需要提供LUA C API解决方案!:P
以下脚本(使用Lua 5.1.4测试,应该在5.2中工作)执行您在对Shmil-The-Cat的答案的评论中所描述的内容:
print("Please enter your name:")
name = io.read()
print("You entered '" .. name .. "'")
Run Code Online (Sandbox Code Playgroud)
该io.read函数有一个默认参数,"*l"它意味着从打开的文件中读取下一行,跳过行尾.默认情况下,打开文件stdin可以使用该io.open文件进行更改.
有关该io库的更多详细信息,请参阅在线Lua参考手册的6.8节,该手册可在http://www.lua.org/manual/5.2/manual.html#6.8上找到.您可能还想阅读Lua编程(PIL)的I/O章节,可以在http://www.lua.org/pil/21.html找到.
| 归档时间: |
|
| 查看次数: |
3418 次 |
| 最近记录: |