diff options
author | Ronan Collobert <ronan@collobert.com> | 2014-03-04 18:45:38 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2014-03-04 18:45:38 +0400 |
commit | e49170d4ae312625d10624f335b26a54a11121e0 (patch) | |
tree | bbcfa5db606d1a080dae8b52c03b577b3f2bb01c /README.md | |
parent | 88335e2b18ff364557fa15c494e7efcbcc688288 (diff) |
doc: per-rule check
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -255,6 +255,36 @@ hello world nil ``` +### Specific per-rule check + +It is possible to add an extra specific checking function for a given checking +rule, with the `check` option. This function will be called (with the corresponding argument) +in addition to the standard type checking. This can be useful for refined argument selection: +```lua +check = argcheck{ + {name="x", type="number", help="a number between one and ten", + check=function(x) + return x >= 1 and x <= 10 + end} +} + +function addfive(...) + local x = check(...) + print(string.format('%f + 5 = %f', x, x+5)) +end + +> addfive(3) +3.000000 + 5 = 8.000000 + +> addfive(11) +stdin:2: invalid arguments + +arguments: +{ + x = number -- a number between one and ten +} +``` + ### Named arguments Argcheck handles named argument calls. Following the previous example, both |