Named Arguments
- Arguments are passed in Lua by position
- First argument goes to first parameter etc.
- Arguments can be given names by instead passing a table
- The table will have name value pairs
- Thus the arguments being in a table can have associated names
An example of passing both types of arguments is given below
local arguments = {planets = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"}, stars = {"Sun", "Rigel", "Altair"}} local celestialType = "planets" function printCelestialType (argTable, printType) local theType = nil if printType == "planets" then theType = "planets" else theType = "stars" end tableToPrint = argTable[theType] for index, value in pairs(tableToPrint) do print (value) end end printCelestialType(arguments, celestialType)