« Introduction au Lua/Fonctions Table » : différence entre les versions

Contenu supprimé Contenu ajouté
Ligne 61 :
== Understand Your Lua Script ==
To understand your Lua script:
# <code>local numbers = {}</code> defines an empty table variable named <code>numbers</code>.
# <code>math.randomseed(os.time())</code> seeds the Lua random number generator with the current server operating system elapsed time in seconds.
#* If the random number generator is not seeded, it will return the same sequence of numbers every time.
#* The MediaWiki software caches page results. It is necessary to purge the server page cache to see new results. See {{tlx|Purge}} for more information.
# <code>for i = 1, 10, 1 do</code> creates a loop code block that will repeat <code>10</code> times.
# <code>table.insert(numbers, math.random(1, 10))</code> calls the <code>math</code> library <code>random</code> function to retrieve a random number between <code>1</code> and <code>10</code> and then inserts that value into the <code>numbers</code> table.
# <code>table.concat(numbers, ', ')</code> retrieves the values in the table <code>numbers</code> and converts them into a string concatenated with <code>', '</code> separators between each value.
# <code>table.sort(numbers)</code> sorts the <code>numbers</code> table in ascending order.
 
== Conclusion ==