Optimized uvl.datatypes

This commit is contained in:
Steven Barth 2008-09-09 15:39:17 +00:00
parent c287c8ca7e
commit 9a8cd55c36

View file

@ -14,11 +14,14 @@ $Id$
]]-- ]]--
module( "luci.uvl.datatypes", package.seeall ) local fs = require "luci.fs"
local ip = require "luci.ip"
local math = require "math"
local util = require "luci.util"
require("luci.fs") local tonumber = tonumber
require("luci.ip")
require("luci.util") module "luci.uvl.datatypes"
function boolean( val ) function boolean( val )
@ -59,7 +62,7 @@ end
function ip4addr( val ) function ip4addr( val )
if val then if val then
return luci.ip.IPv4(val) and true or false return ip.IPv4(val) and true or false
end end
return false return false
@ -72,7 +75,7 @@ end
function ip6addr( val ) function ip6addr( val )
if val then if val then
return luci.ip.IPv6(val) and true or false return ip.IPv6(val) and true or false
end end
return false return false
@ -102,7 +105,7 @@ function macaddr( val )
"^[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+:" .. "^[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+:" ..
"[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+$" "[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+$"
) then ) then
local parts = luci.util.split( val, ":" ) local parts = util.split( val, ":" )
for i = 1,6 do for i = 1,6 do
parts[i] = tonumber( parts[i], 16 ) parts[i] = tonumber( parts[i], 16 )
@ -134,7 +137,7 @@ function string( val )
end end
function directory( val, seen ) function directory( val, seen )
local s = luci.fs.stat( val ) local s = fs.stat( val )
seen = seen or { } seen = seen or { }
if s and not seen[s.ino] then if s and not seen[s.ino] then
@ -142,7 +145,7 @@ function directory( val, seen )
if s.type == "directory" then if s.type == "directory" then
return true return true
elseif s.type == "link" then elseif s.type == "link" then
return directory( luci.fs.readlink(val), seen ) return directory( fs.readlink(val), seen )
end end
end end
@ -150,7 +153,7 @@ function directory( val, seen )
end end
function file( val, seen ) function file( val, seen )
local s = luci.fs.stat( val ) local s = fs.stat( val )
seen = seen or { } seen = seen or { }
if s and not seen[s.ino] then if s and not seen[s.ino] then
@ -158,7 +161,7 @@ function file( val, seen )
if s.type == "regular" then if s.type == "regular" then
return true return true
elseif s.type == "link" then elseif s.type == "link" then
return file( luci.fs.readlink(val), seen ) return file( fs.readlink(val), seen )
end end
end end