select()

类型 函数
(全局变量)
返回值 (各异)
修订版 版本 2024.3703
关键字 select

概览

如果 index 是一个数字,则 select() 会返回从第 index 个参数开始的所有参数。否则,index 必须为字符串 #,而 select() 会返回它接收到的多余参数的总数。

语法

select( index, ... )
index (必需)

数字 或者 字符串该参数可以为一个数字,在这种情况下,select() 会返回从第 index 个参数开始的所有参数。否则,index 必须为字符串 #,而 select() 会返回它接收到的多余参数的总数。

示例

-- This example demonstrates how to access individual return values
-- from a function that returns multiple values

print(string.find("hello hello", " hel"))         --> 6  9
print(select(1, string.find("hello hello", " hel"))) --> 6
print(select(2, string.find("hello hello", " hel"))) --> 9
-- This example prints the total number of extra arguments passed to the `select()` function
print(select("#", a,b,c)) --> 3