summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/cbi
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2011-06-17 10:52:49 +0000
committerJo-Philipp Wich <jow@openwrt.org>2011-06-17 10:52:49 +0000
commit354aeb44f67d716d44fa7c03617e48265a28dd3f (patch)
tree900c382ab7596f6952ccceccee2e2d72774621da /libs/web/luasrc/cbi
parent64c6f8f4b64265a04c54af95432736464adc5ae4 (diff)
libs/web: add new datatypes min(...), max(...) and neg_network_ip4addr
Diffstat (limited to 'libs/web/luasrc/cbi')
-rw-r--r--libs/web/luasrc/cbi/datatypes.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua
index d4603cf2a..6640db639 100644
--- a/libs/web/luasrc/cbi/datatypes.lua
+++ b/libs/web/luasrc/cbi/datatypes.lua
@@ -227,6 +227,13 @@ function uciname(val)
return (val:match("^[a-zA-Z0-9_]+$") ~= nil)
end
+function neg_network_ip4addr(val)
+ if type(v) == "string" then
+ v = v:gsub("^%s*!", "")
+ return (uciname(v) or ip4addr(v))
+ end
+end
+
function range(val, min, max)
val = tonumber(val)
min = tonumber(min)
@@ -238,3 +245,25 @@ function range(val, min, max)
return false
end
+
+function min(val, min)
+ val = tonumber(val)
+ min = tonumber(min)
+
+ if val ~= nil and min ~= nil then
+ return (val >= min)
+ end
+
+ return false
+end
+
+function max(val, max)
+ val = tonumber(val)
+ max = tonumber(max)
+
+ if val ~= nil and max ~= nil then
+ return (val <= max)
+ end
+
+ return false
+end