lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, Jun 13, 2012 at 2:11 PM, Patrick Rapin <> wrote:
> With a metatable and some helper functions, you can have almost what you need :
> function person(args)
>  args = get_args(args, {
>    name = required "Please provide a name", -- your name
>    age = check_type("number"), -- your age
>    address = "(no street address)", -- your street address
>   })
>   print(, args.age, args.address)
> end
> person{name = "John Doo", age=56}
> --> John Doo 56  (no street address)
> person{}
> -- Error: Please provide a name

Hmmm.. Automating required arguments is neat and useful, but I see it
as different than what I see as perhaps two different language
changes/enhancements/(painted toenails):

Providing named argument syntax for defining function arguments,
similar to the named argument syntax used to call functions

Providing a way to place default argument assignments within the
argument definition, as an alternative to re-assigning them as a
second step within the function.