summaryrefslogtreecommitdiffhomepage
path: root/libs/uvl/luasrc
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-11-02 21:42:16 +0000
committerSteven Barth <steven@midlink.org>2008-11-02 21:42:16 +0000
commitde80e2a708653e825434753a1b48559648942a3b (patch)
tree6aa9fb4b01f7ec4d5d48fbb248d0eeb260c5b9da /libs/uvl/luasrc
parent9e4c03a9c35a2ff29030a645bccf5984dd2978d6 (diff)
Added UVL values minlength, maxlength, minimum, maximum
Diffstat (limited to 'libs/uvl/luasrc')
-rw-r--r--libs/uvl/luasrc/uvl.lua27
-rw-r--r--libs/uvl/luasrc/uvl/errors.lua1
2 files changed, 28 insertions, 0 deletions
diff --git a/libs/uvl/luasrc/uvl.lua b/libs/uvl/luasrc/uvl.lua
index 683d7a9bb..8275dbbe1 100644
--- a/libs/uvl/luasrc/uvl.lua
+++ b/libs/uvl/luasrc/uvl.lua
@@ -334,6 +334,30 @@ function UVL._validate_option( self, option, nodeps )
return false, option:error(ERR.OPT_DATATYPE(option, dt))
end
end
+
+ if option:scheme('minlength') then
+ if #val < option:scheme('minlength') then
+ return false, option:error(ERR.OPT_RANGE(option))
+ end
+ end
+
+ if option:scheme('maxlength') then
+ if #val > option:scheme('maxlength') then
+ return false, option:error(ERR.OPT_RANGE(option))
+ end
+ end
+
+ if option:scheme('minimum') then
+ if val < option:scheme('minimum') then
+ return false, option:error(ERR.OPT_RANGE(option))
+ end
+ end
+
+ if option:scheme('maximum') then
+ if val > option:scheme('maximum') then
+ return false, option:error(ERR.OPT_RANGE(option))
+ end
+ end
if not nodeps then
local ok, err = dependencies.check( self, option )
@@ -582,6 +606,9 @@ function UVL._parse_var(self, scheme, k, v)
t.valueof = type(v2) == "table" and v2 or {v2}
elseif k == "required" then
t[k] = _bool(v2)
+ elseif k == "minlength" or k == "maxlength"
+ or k == "minimum" or k == "maximum" then
+ t[k] = tonumber(v2)
else
t[k] = t[k] or v2
end
diff --git a/libs/uvl/luasrc/uvl/errors.lua b/libs/uvl/luasrc/uvl/errors.lua
index 242965ddc..9cd8d19cf 100644
--- a/libs/uvl/luasrc/uvl/errors.lua
+++ b/libs/uvl/luasrc/uvl/errors.lua
@@ -66,6 +66,7 @@ ERRCODES = {
{ 'OPT_NOTLIST', 'Option "%i" is defined as list but stored as plain value' },
{ 'OPT_DATATYPE', 'Option "%i" has unknown datatype "%1"' },
{ 'OPT_NOTFOUND', 'Option "%p.%s.%o" not found in config' },
+ { 'OPT_RANGE', 'Option "%p.%s.%o" is not within the specified range' },
{ 'DEP_NOTEQUAL', 'Dependency (%1) failed:\nOption "%i" is not eqal "%2"' },
{ 'DEP_NOVALUE', 'Dependency (%1) failed:\nOption "%i" has no value' },