diff options
author | Ronan Collobert <ronan@collobert.com> | 2013-02-23 16:35:05 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2013-02-23 16:35:05 +0400 |
commit | 5845cffcf44cb010ea9d1529c1acc0f81c0891ac (patch) | |
tree | 5f57705debf0b265c2d79688cae6e80fdfcc8db1 /README.md | |
parent | 4973996484ccb7ac2851dd47a9ad24b57a3cb14b (diff) |
more on README
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -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 +``` |