what does the select function do?
it gets the value of the table in index and the other stuff beyond like string.sub but to tables
it is a useless function too, might be useful when
how it works
local function Select(Index, ...)
local Length = #{...}
if Index == "#" then
return Length
elseif Index < 0 or Index > Length then
Index = Length
end
local Results = {}
for i=Index, Length do
table.insert(Results, ({...})[i])
end
return table.unpack(Results)
end
print(select(1, "1", "2", "9")) -- "1", "2", "9"
print(select(2, "1", "2", "9")) -- "2", "9"
print(select(3, "1", "2", "9")) -- "9"
print(select("#", "1", "2", "9")) -- "3" because its #Table oops
print(select(-1, "1", "2", "9")) -- "9"
6 Likes
I mean in reality it just retrieves the values from a tuple from given index to the end of the tuple
2 Likes
thanks but how can you know how a built-in function works ( its source code).
- command bar
- function documentation
and using the little info, create one myself if you can
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.