luci-compat: fix evaluating or()
and and()
datatype expressions
Fixes: #5705 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
315a592d9b
commit
03bb0e2493
1 changed files with 28 additions and 13 deletions
|
@ -13,34 +13,49 @@ module "luci.cbi.datatypes"
|
||||||
|
|
||||||
|
|
||||||
_M['or'] = function(v, ...)
|
_M['or'] = function(v, ...)
|
||||||
local i
|
local i, n = 1, select('#', ...)
|
||||||
for i = 1, select('#', ...), 2 do
|
while i <= n do
|
||||||
local f = select(i, ...)
|
local f = select(i, ...)
|
||||||
local a = select(i+1, ...)
|
|
||||||
if type(f) ~= "function" then
|
if type(f) ~= "function" then
|
||||||
if f == v then
|
i = i + 1
|
||||||
|
local c = v
|
||||||
|
if type(f) == "number" then
|
||||||
|
c = tonumber(c)
|
||||||
|
end
|
||||||
|
if f == c then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
i = i + 2
|
||||||
|
local a = select(i-1, ...)
|
||||||
|
if f(v, unpack(a)) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
i = i - 1
|
|
||||||
elseif f(v, unpack(a)) then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
_M['and'] = function(v, ...)
|
_M['and'] = function(v, ...)
|
||||||
local i
|
local i, n = 1, select('#', ...)
|
||||||
for i = 1, select('#', ...), 2 do
|
while i <= n do
|
||||||
local f = select(i, ...)
|
local f = select(i, ...)
|
||||||
local a = select(i+1, ...)
|
|
||||||
if type(f) ~= "function" then
|
if type(f) ~= "function" then
|
||||||
if f ~= v then
|
i = i + 1
|
||||||
|
local c = v
|
||||||
|
if type(f) == "number" then
|
||||||
|
c = tonumber(c)
|
||||||
|
end
|
||||||
|
if f ~= c then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
i = i - 1
|
i = i - 1
|
||||||
elseif not f(v, unpack(a)) then
|
else
|
||||||
return false
|
i = i + 2
|
||||||
|
local a = select(i-1, ...)
|
||||||
|
if not f(v, unpack(a)) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue