如何使函数返回不仅仅是真或假?

请注意,每个值必须能够单独调用 :D

function test()
  input = io.read()
  if input == "1" then
    return -- 值一
  elseif input == "2" then
    return -- 值二
  elseif input == "3" then
    return -- 值三
  end
end
点赞
用户188331
用户188331

如何:

function test()  // 定义函数 test
  input = io.read()  // 读取输入
  if input == "1" then
    return 1 -- 值为一
  elseif input == "2" then
    return 2 -- 值为二
  elseif input == "3" then
    return 3 -- 值为三
  end
end
2013-12-21 03:09:58
用户1143300
用户1143300
函数 `test()` 会读取用户输入的字符串并将其转换为数字返回。

示例:

```lua
local num = test()  -- 用户输入 123,函数返回 123

```

2013-12-21 03:11:48