Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/argcheck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Collobert <ronan@collobert.com>2013-02-24 19:59:10 +0400
committerRonan Collobert <ronan@collobert.com>2013-02-24 19:59:10 +0400
commit9417ee845ff934489a93e264c6ac7da61c9b23fb (patch)
tree3446c78dfebf3fd34cad4280f269a342c4158ceb /README.md
parentc065f4fb0f341769dee7641662868283d0540aae (diff)
more doc
Diffstat (limited to 'README.md')
-rw-r--r--README.md23
1 files changed, 22 insertions, 1 deletions
diff --git a/README.md b/README.md
index 0f4226d..4433a6b 100644
--- a/README.md
+++ b/README.md
@@ -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")
```