Lua如何请求多行输入?

我试图在个人时间内创建一个“银行”类型的基本帐户创建器,但遇到了问题。我创建了一个名为“newAccount”的文件,以此来创建新帐户,但当我运行它时,它只会询问第一个问题,然后停止工作。

这是我到目前为止的代码。

print("What is the user's name?")
name = read()
file = io.open(name ,"w")
file:write(1, "Name: " + name, "\n")
print("What do they owe?")
owe = read()
file:write(2, "Owe: " + owe, "\n")
print("What is their account balance?")
balance = read()
file:write(3, "Balance: " + balance, "\n")
file:close(name)

运行停止后,会显示以下内容:

newAccount:4: 尝试在字符串和字符串上执行算术__add操作
App has finished, press any key to exit."
点赞
用户1009479
用户1009479

Lua 使用 .. 来连接字符串,而不是 +。请将以下代码更改:

"Name: " + name

更改为:

"Name: " .. name
2015-06-05 02:49:30