A partir du manuel Lua:
If index is a number, returns all arguments after argument number
index. Otherwise, index must be the string "#", and select returns
the total number of extra arguments it received.
Lua has built in multiple arguments, que vous pouvez convertir en une table si vous avez vraiment besoin:
function multiple_args(...)
local arguments = {...} -- pack the arguments in a table
-- do something --
return unpack(arguments) -- return multiple arguments from a table (unpack)
end
Enfin, si vous transmettre "#" comme index, la fonction renvoie un nombre de plusieurs arguments d:
print(select("#")) --> 0
print(select("#", {1, 2, 3})) --> 1 (single table as argument)
print(select("#", 1, 2, 3)) --> 3
print(select("#", {1,2,3}, 4, 5, {6,7,8}) --> 4 (a table, 2 numbers, another table)
Voir cette website.
BTW, la boucle peut être remplacée par 'str = table.concat ({str, ...}," \ t ")'. – lhf
Je suggérerais d'utiliser 'file: write()' ici au lieu de concaténer la chaîne, puis d'appeler 'os.execute()' - serait beaucoup plus rapide. Vous pouvez vouloir "vider" le fichier à la fin de la ligne. –
merci pour les conseils d'optimisation – AlexStack