How To: Lua named arguments

In serveral programming languages offer a system, where you can have named argument in functions. Basically named arguments are arguments which you can target with a name. As a example in C# you can write instead of this: you can write this:

This not only improves readablity, but it also gives you more freedom. You're not forced to write the arguments in a specific order and you can even let some arguments out (if they are marked as "optional")

Named arguments in lua
So lua doesn't offer such a system directly. However, you can use a table to apply this technique. In LunaLua there are several functions which accepts named arguments. The signature for those function are always the same:

To call this function you can write this: or you can use an alternative order: In this example foo can accept as a named argument:
 * bar (A string value)
 * baz (A number value)
 * qux (A number value [Optional value] )

You probably noticed that there are no round brackets used to call the function. You only need round brackets if you have more than on argument.