-- 无返回值 function fun0() end -- 一个返回值 function fun1() return 1 end -- 二个返回值 function fun2() return 1, 2 end -- 三个及多个返回值 function fun3() return 1, 2, 3 end
fun0() fun1() fun2() fun3()
if (fun2() == 1) then -- 只返回1 print(fun2()) -- 打印1, 2 print(fun2(), "end") -- 打印1, "end" -- 如果想强制只返回一个值,则可以用括号 "()" 把表达式括起来即可: print((fun2())) -- 打印1 end
x = fun0() -- x = nil x = fun1() -- x = 1 x = fun2() -- x = 1, 2丢弃 x = fun3() -- x = 1, 2, 3 丢弃 x, y = fun1() -- x = 1, y = nil x, y = fun2() -- x = 1, y = 2 x, y = fun3() -- x = 1, y = 2, 3 丢弃 x, y, z = fun2() -- x = 1, y = 2, z = nil x, y, z = fun3() -- x = 1, y = 2, z = 3
原文地址:http://blog.csdn.net/xufeng0991/article/details/42640769