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-23 16:35:05 +0400
committerRonan Collobert <ronan@collobert.com>2013-02-23 16:35:05 +0400
commit5845cffcf44cb010ea9d1529c1acc0f81c0891ac (patch)
tree5f57705debf0b265c2d79688cae6e80fdfcc8db1 /README.md
parent4973996484ccb7ac2851dd47a9ad24b57a3cb14b (diff)
more on README
Diffstat (limited to 'README.md')
-rw-r--r--README.md29
1 files changed, 27 insertions, 2 deletions
diff --git a/README.md b/README.md
index b632382..fb73c47 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ check arguments. Assume you have a function which requires a unique number
argument:
```lua
function addfive(x)
- print(string.format('%f + 5 = %f', x, x+5)
+ print(string.format('%f + 5 = %f', x, x+5))
end
```
You can make sure everything goes fine by doing:
@@ -42,7 +42,32 @@ You can make sure everything goes fine by doing:
addfive = argcheck(
{{name="x", type="number"}},
function(x)
- print(string.format('%f + 5 = %f', x, x+5)
+ print(string.format('%f + 5 = %f', x, x+5))
end
)
```
+If a user try to pass a wrong argument, too many arguments, or no arguments
+at all, `argcheck` will complain:
+```lua
+> arguments:
+{
+ x = number --
+}
+
+[string "return function()..."]:8: invalid arguments
+```
+Simple argument types like `number`, `string` or `boolean` can have defaults:
+```lua
+addfive = argcheck(
+ {{name="x", type="number", default=0}},
+ function(x)
+ print(string.format('%f + 5 = %f', x, x+5))
+ end
+)
+```
+In which case, if the argument is missing, `argcheck` will pass the default
+one to your function:
+```lua
+> addfive()
+0.000000 + 5 = 5.000000
+```