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>2014-02-28 19:28:35 +0400
committerRonan Collobert <ronan@collobert.com>2014-02-28 19:28:35 +0400
commitab439b5e7c89588230635226837550ac07abc2ee (patch)
tree54e287a60d1483c6532aba721d85ebe3b8fcb0e3
parentfce08c8ba32afdb62f10ab24edc8812700d578cc (diff)
opt argument can be also nil...
-rw-r--r--init.lua6
1 files changed, 5 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index 90b57d6..6594c9b 100644
--- a/init.lua
+++ b/init.lua
@@ -69,7 +69,11 @@ local function generateargcheck__(txt, argdefs, funcname, vars, named)
end
argdef.luaname = named and string.format('arg.%s', argdef.name) or string.format('select(%d, ...)', argidx)
if argdef.check and argdef:check() then
- table.insert(checks, argdef:check())
+ if argdef.opt then
+ table.insert(checks, string.format("(type(%s) == 'nil' or %s)", argdef.luaname, argdef:check()))
+ else
+ table.insert(checks, argdef:check())
+ end
end
if argdef.read then
if argdef:read() then