aboutsummaryrefslogtreecommitdiff
path: root/valua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'valua.lua')
-rw-r--r--valua.lua24
1 files changed, 12 insertions, 12 deletions
diff --git a/valua.lua b/valua.lua
index d4d62b9..924b175 100644
--- a/valua.lua
+++ b/valua.lua
@@ -41,12 +41,12 @@ function valua:new(obj)
--saves a function named _<index> with its args in a funcs table, to be used later when validating
return function(...)
local args = pack(...)
- if k == 'optional' then
- obj.allow_nil = true
- else
- local f = function(value) return valua['_'..k](value, unpack(args, 1, args.n)) end
- tinsert(t.funcs,f)
- end
+ if k == 'optional' then
+ obj.allow_nil = true
+ else
+ local f = function(value) return valua['_'..k](value, unpack(args, 1, args.n)) end
+ tinsert(t.funcs,f)
+ end
return t
end
end
@@ -54,12 +54,12 @@ function valua:new(obj)
-- __call will run only when the value is validated
self.__call = function(t,value)
local res = true
- local err = nil
- local fres
+ local err = nil
+ local fres
- if value == nil and t.allow_nil then
- return res, err
- end
+ if value == nil and t.allow_nil then
+ return res, err
+ end
-- iterates through all chained validations funcs that were packed, passing the value to be validated
for _,f in ipairs(t.funcs) do
@@ -74,7 +74,7 @@ function valua:new(obj)
return res,err
end
obj.funcs = {}
- obj.allow_nil = false
+ obj.allow_nil = false
return obj
end
--