diff options
author | Ronan Collobert <ronan@collobert.com> | 2013-02-24 19:59:10 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2013-02-24 19:59:10 +0400 |
commit | 9417ee845ff934489a93e264c6ac7da61c9b23fb (patch) | |
tree | 3446c78dfebf3fd34cad4280f269a342c4158ceb /README.md | |
parent | c065f4fb0f341769dee7641662868283d0540aae (diff) |
more doc
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -154,6 +154,27 @@ Give a number, it adds 5. Amazing. [string "return function()..."]:13: invalid arguments ``` +### Default arguments defaulting to another argument + +Arguments can have a default value coming from another argument, with the +`defaulta` option. In the following +```lua +mul = argcheck( + {{name="x", type="number"}, + {name="y", type="number", defaulta="x"}}, + function(x, y) + print(string.format('%f x %f = %f', x, y, x*y)) + end +) +``` +argument `y` will take the value of `x` if it is not passed during the function call: +```lua +> mul(3,4) +3.000000 x 4.000000 = 12.000000 +> mul(3) +3.000000 x 3.000000 = 9.000000 +``` + ### Optional arguments Arguments with a default value can be seen as optional. However, as they @@ -183,7 +204,7 @@ nil ### Named arguments -Argcheck handles named argument. Following the previous example, both +Argcheck handles named argument calls. Following the previous example, both ```lua addfive(1, "hello world") ``` |