Lua 有人能解释多个局部变量吗

Lua 有人能解释多个局部变量吗,lua,Lua,4号线做什么?如果我用 1 function getCoordinates() 2 return 12, 55, 123 3 end 4 local x, y, z = getCoordinates() 5 print(x, y, z) output: 12 55 123 我得到12比12 即使我将打印语句更改为 local x= getCoordinates() local y= getCoordinates() local z= getCoordinates() 仍然得到

4号线做什么?如果我用

1 function getCoordinates()
2   return 12, 55, 123
3 end

4 local x, y, z = getCoordinates()
5 print(x, y, z)  

output:
12  55  123
我得到12比12

即使我将打印语句更改为

local x= getCoordinates()
local y= getCoordinates()
local z= getCoordinates()
仍然得到

十二, 无
12

函数
getCoordinates
返回3个值。您的
局部x、y、z
声明将这些值解压为3个新变量


当您将
getCoordinates()
分配给单个变量时,最后两个值会被自动删除,因此所有3个变量都会得到
12
的值。(我不知道如何获得
y
nil

函数
getCoordinates
返回3个值。您的
局部x、y、z
声明将这些值解压为3个新变量

当您将
getCoordinates()
分配给单个变量时,最后两个值会被自动删除,因此所有3个变量都会得到
12
的值。(我不知道你怎么能得到
y
nil

print(x)
print(y)
print(z)