Named Arguments
Instead of positional arguments, you can use the names of arguments you want to set:
local function process_file(file, mode = "r", version = 1)
print($"Processing {file} with mode '{mode}' and version {version}")
end
process_file(file = "hello.txt", version = 2) -- "Processing hello.txt with mode 'r' and version 2"
Try It Yourself
Note that this example also makes use of default arguments and string interpolation.
Mixing arguments
You can use positional arguments for the first few arguments and then use named arguments for the latter ones, for example:
local function process_file(file, mode = "r", version = 1)
print($"Processing {file} with mode '{mode}' and version {version}")
end
process_file("hello.txt", version = 2) -- "Processing hello.txt with mode 'r' and version 2"
Try It Yourself
Limitations
This feature is implemented entirely in the parser and therefore only works for local functions at the moment.